|
| 1 | +=========== |
| 2 | + Functions |
| 3 | +=========== |
| 4 | + |
| 5 | +.. highlight:: console |
| 6 | + |
| 7 | +.. contents:: Content |
| 8 | + :depth: 2 |
| 9 | + :local: |
| 10 | + :backlinks: top |
| 11 | + |
| 12 | +.. _cmd-init: |
| 13 | + |
| 14 | +pyarmor init |
| 15 | +============ |
| 16 | + |
| 17 | +.. _create-project: |
| 18 | + |
| 19 | +Create Project |
| 20 | +-------------- |
| 21 | + |
| 22 | +.. graphviz:: |
| 23 | + :caption: Create Project |
| 24 | + :align: center |
| 25 | + :name: g-create-project |
| 26 | + |
| 27 | + digraph G { |
| 28 | + node [shape=box, style=rounded, target="_top"] |
| 29 | + rankdir=LR |
| 30 | + |
| 31 | + opts [shape=record |
| 32 | + label="{-C|-s|-r|-x}"] |
| 33 | + init [label="pyarmor init"] |
| 34 | + conf [label="配置文件 .pyarmor/config"] |
| 35 | + |
| 36 | + init -> opts [label="传入选项" dir=back arrowtail=curve] |
| 37 | + rank=same { init -> conf [label="写入"] } |
| 38 | + } |
| 39 | + |
| 40 | +.. _append-project-item: |
| 41 | + |
| 42 | +增加脚本/模块/包到工程 |
| 43 | +---------------------- |
| 44 | + |
| 45 | +.. graphviz:: |
| 46 | + :caption: 增加脚本/模块/包到工程 |
| 47 | + :align: center |
| 48 | + :name: g-append-project-item |
| 49 | + |
| 50 | + digraph G { |
| 51 | + node [shape=box, style=rounded, target="_top"] |
| 52 | + rankdir=LR |
| 53 | + |
| 54 | + opts [shape=record |
| 55 | + label="{-e|-m|-p}"] |
| 56 | + init [label="pyarmor init"] |
| 57 | + conf [label="配置文件 .pyarmor/config"] |
| 58 | + |
| 59 | + init -> opts [label="传入选项" dir=back arrowtail=curve] |
| 60 | + rank=same { init -> conf [label="写入"] } |
| 61 | + } |
| 62 | + |
| 63 | +.. _cmd-env: |
| 64 | + |
| 65 | +pyarmor env |
| 66 | +=========== |
| 67 | + |
| 68 | +.. _show-project-info: |
| 69 | + |
| 70 | +显示工程配置 |
| 71 | +------------ |
| 72 | + |
| 73 | +.. graphviz:: |
| 74 | + :caption: 显示工程配置 |
| 75 | + :align: center |
| 76 | + :name: g-show-project-info |
| 77 | + |
| 78 | + digraph G { |
| 79 | + node [shape=box, style=rounded, target="_top"] |
| 80 | + |
| 81 | + init [label="pyarmor env -p info"] |
| 82 | + conf [label="配置文件 .pyarmor/config"] |
| 83 | + info [label="工程信息"] |
| 84 | + |
| 85 | + rank=same { conf -> init [label="传入配置" arrowhead=curve] } |
| 86 | + init -> info [label="显示"] |
| 87 | + } |
| 88 | + |
| 89 | +.. _edit-project-info: |
| 90 | + |
| 91 | +修改工程配置 |
| 92 | +------------ |
| 93 | + |
| 94 | +.. graphviz:: |
| 95 | + :caption: 修改工程配置 |
| 96 | + :align: center |
| 97 | + :name: g-edit-project-info |
| 98 | + |
| 99 | + digraph G { |
| 100 | + node [shape=box, style=rounded, target="_top"] |
| 101 | + rankdir=LR |
| 102 | + |
| 103 | + opts [label="工程选项" |
| 104 | + href="../../docs/zh/configuration.html"] |
| 105 | + env [label="pyarmor env -p set opt value"] |
| 106 | + conf [label="配置文件 .pyarmor/config"] |
| 107 | + |
| 108 | + env -> opts [label="传入选项" dir=back arrowtail=curve] |
| 109 | + rank=same { env -> conf [label="写入"] } |
| 110 | + } |
| 111 | + |
| 112 | +.. _cmd-build: |
| 113 | + |
| 114 | +pyarmor build |
| 115 | +============= |
| 116 | + |
| 117 | +.. _list-project-items: |
| 118 | + |
| 119 | +列出工程中包含的脚本/模块/包 |
| 120 | +---------------------------- |
| 121 | + |
| 122 | +.. graphviz:: |
| 123 | + :caption: 列出工程中包含的脚本/模块/包 |
| 124 | + :align: center |
| 125 | + :name: g-list-project-items |
| 126 | + |
| 127 | + digraph G { |
| 128 | + node [shape=box, style=rounded, target="_top"] |
| 129 | + |
| 130 | + conf [label="配置文件 .pyarmor/config" |
| 131 | + href="../../docs/zh/configuration.html"] |
| 132 | + build [label="pyarmor build --list"] |
| 133 | + items [label="显示工程中包含的所有脚本名称"] |
| 134 | + |
| 135 | + conf -> build [label="传入配置" arrowhead=curve] |
| 136 | + build -> items [label="根据项目选项配置进行搜索和过滤"] |
| 137 | + } |
| 138 | + |
| 139 | +.. _project-build-rft: |
| 140 | + |
| 141 | +生成重构型脚本 |
| 142 | +-------------- |
| 143 | + |
| 144 | +.. graphviz:: |
| 145 | + :caption: 生成重构型脚本 |
| 146 | + :align: center |
| 147 | + :name: g-project-build-rft |
| 148 | + |
| 149 | + digraph G { |
| 150 | + node [shape=box, style=rounded, target="_top"] |
| 151 | + |
| 152 | + build [label="pyarmor build --rft" |
| 153 | + style="filled,rounded" |
| 154 | + fillcolor="wheat"] |
| 155 | + join1 [shape=point] |
| 156 | + |
| 157 | + items [label="依次处理每一个脚本"] |
| 158 | + |
| 159 | + conf [label="工程属性\n存放在 .pyarmor/config 中"] |
| 160 | + |
| 161 | + rules [shape=plaintext |
| 162 | + label="工程的重构选项\n存放在 .pyarmor/config 中"] |
| 163 | + autofix [shape=plain |
| 164 | + label="自动生成的重构规则\n存放在 .pyarmor/project/rft_autofix.rules"] |
| 165 | + |
| 166 | + p1 [label="应用重构规则"] |
| 167 | + rft [label="生成重构脚本"] |
| 168 | + |
| 169 | + build -> join1 |
| 170 | + join1 -> conf [dir=none] |
| 171 | + join1 -> items [label="得到工程中的脚本列表"] |
| 172 | + items -> p1 |
| 173 | + rank=same { p1 -> rft } |
| 174 | + |
| 175 | + p1 -> rules [arrowtail=curve dir=back] |
| 176 | + p1 -> autofix [arrowtail=curve dir=back] |
| 177 | + } |
| 178 | + |
| 179 | +.. _project-rft-autofix: |
| 180 | + |
| 181 | +使用自动修正模式重构复杂脚本 |
| 182 | +---------------------------- |
| 183 | + |
| 184 | +Pyarmor 目前实现三种自动修改模式 |
| 185 | + |
| 186 | +- :ref:`模式 1: 使用最简单,一般不需要人工增加规则,但是可能很多属性都没有重命名 <g-project-rft-autofix-1>` |
| 187 | +- :ref:`模式 2: 使用较为复杂的方式,大部分的属性都会重命名,但是有时候需要人工修改规则 <g-project-rft-autofix-2>` |
| 188 | +- :ref:`模式 3: 使用最麻烦,但是能够重命名绝大部分属性,一般必须要人工修改规则 <g-project-rft-autofix-3>` |
| 189 | + |
| 190 | +.. graphviz:: |
| 191 | + :caption: 重构复杂脚本自动修正模式一 |
| 192 | + :align: center |
| 193 | + :name: g-project-rft-autofix-1 |
| 194 | + |
| 195 | + digraph G { |
| 196 | + node [shape=box, style=rounded, target="_top"] |
| 197 | + |
| 198 | + build [label="pyarmor build --autofix 1" |
| 199 | + style="filled,rounded" |
| 200 | + fillcolor="wheat"] |
| 201 | + join1 [shape=point] |
| 202 | + |
| 203 | + items [label="依次处理每一个脚本"] |
| 204 | + |
| 205 | + conf [label="工程属性\n存放在 .pyarmor/config 中"] |
| 206 | + |
| 207 | + rules [shape=plaintext |
| 208 | + label="工程的重构选项\n存放在 .pyarmor/config 中"] |
| 209 | + autofix [shape=component |
| 210 | + style="filled" |
| 211 | + fillcolor="tan" |
| 212 | + label="生成重构规则\n所有未知属性都不进行重命名\n保存规则到 .pyarmor/project/rft_autofix.rules"] |
| 213 | + |
| 214 | + p1 [label="应用重构规则"] |
| 215 | + rft [label="尝试重构脚本\n如果某一个属性无法确定是否需要重命名\n那么记录到未知属性表中"] |
| 216 | + |
| 217 | + loop [label="合并所有脚本生成的未知属性表"] |
| 218 | + |
| 219 | + build -> join1 |
| 220 | + join1 -> conf [dir=none] |
| 221 | + join1 -> items [label="得到工程中的脚本列表"] |
| 222 | + items -> p1 |
| 223 | + rank=same { p1 -> rft } |
| 224 | + p1 -> rules [arrowtail=curve dir=back] |
| 225 | + |
| 226 | + rft -> loop -> autofix |
| 227 | + |
| 228 | + rebuild [style="filled,rounded" |
| 229 | + fillcolor="wheat" |
| 230 | + label="再次构建工程\npyarmor build --rft"] |
| 231 | + test [label="运行重构后的脚本\npython dist/foo.py"] |
| 232 | + fb [label="是否出现 AttributeError?"] |
| 233 | + f2 [label="把该名称人工增加到排除列表\npyarmor env -p push rft:exclude_names xxxx"] |
| 234 | + |
| 235 | + autofix -> rebuild -> test -> fb |
| 236 | + |
| 237 | + fb -> f2 [label="提示名称 xxxx 错误"] |
| 238 | + f2 -> rebuild [label="循环修正,直到没有错误" headport=3 tailport=e] |
| 239 | + } |
| 240 | + |
| 241 | +.. graphviz:: |
| 242 | + :caption: 重构复杂脚本自动修正模式二 |
| 243 | + :align: center |
| 244 | + :name: g-project-rft-autofix-2 |
| 245 | + |
| 246 | + digraph G { |
| 247 | + node [shape=box, style=rounded, target="_top"] |
| 248 | + |
| 249 | + build [label="pyarmor build --autofix 2" |
| 250 | + style="filled,rounded" |
| 251 | + fillcolor="wheat"] |
| 252 | + join1 [shape=point] |
| 253 | + |
| 254 | + items [label="依次处理每一个脚本"] |
| 255 | + |
| 256 | + conf [label="工程属性\n存放在 .pyarmor/config 中"] |
| 257 | + |
| 258 | + rules [shape=plaintext |
| 259 | + label="工程的重构选项\n存放在 .pyarmor/config 中"] |
| 260 | + p1 [label="应用重构规则"] |
| 261 | + rft [label="尝试重构脚本\n记录不知道如何处理的属性\n生成未知属性表"] |
| 262 | + |
| 263 | + u1 [label="读取所有内置类型\n例如 int, list 等的属性\n读取重构选项 external_types\n得到所有外部导入类型的属性"] |
| 264 | + un [label="合并内置和外部类型的属性\n生成外部属性表"] |
| 265 | + u1 -> un |
| 266 | + |
| 267 | + autofix [shape=component |
| 268 | + style="filled" |
| 269 | + fillcolor="tan" |
| 270 | + label="生成重构规则\n未知属性和外部属性的交集都不进行重命名\n其他未知属性都进行重命名\n保存规则到 .pyarmor/project/rft_autofix.rules"] |
| 271 | + un -> autofix |
| 272 | + |
| 273 | + build -> join1 |
| 274 | + join1 -> conf [dir=none] |
| 275 | + join1 -> items [label="得到工程中的脚本列表"] |
| 276 | + items -> p1 |
| 277 | + rank=same { p1 -> rft [dir=normal] } |
| 278 | + p1 -> rules [arrowtail=curve dir=back] |
| 279 | + rft -> autofix |
| 280 | + |
| 281 | + rebuild [style="filled,rounded" |
| 282 | + fillcolor="wheat" |
| 283 | + label="再次构建工程\npyarmor build --rft"] |
| 284 | + test [label="运行重构后的脚本\npython dist/foo.py"] |
| 285 | + fb [label="是否出现 AttributeError?"] |
| 286 | + f1 [label="如果该名称是混淆后的名称\n在 .pyarmor/project/rft_autofix.rules 搜索该名称\n找到原来的名称"] |
| 287 | + f2 [label="把原来的名称人工增加到排除列表\npyarmor env -p push rft:exclude_names xxxx"] |
| 288 | + f3 [label="高级修正方法"] |
| 289 | + f4 [label="查看日志文件(Emacs org-mode)\n.pyarmor/rft_autofix.2.org"] |
| 290 | + f5 [label="浏览日志中已经重命名的属性名称\n如果该属性属于外部类型\n那么将该属性增加到配置文件中\npyarmor env -p push external_attrs XXXX"] |
| 291 | + f6 [label="重新开始修正循环\npyarmor build --autofix 2" |
| 292 | + style="filled,rounded" |
| 293 | + fillcolor="wheat"] |
| 294 | + autofix -> rebuild -> test -> fb |
| 295 | + fb -> f1 [label="提示名称 xxxx 错误"] |
| 296 | + f1 -> f2 [label="简单修正方法"] |
| 297 | + f2 -> rebuild [label="循环修正,直到没有错误" tailport=e] |
| 298 | + f1 -> f3 -> f4 -> f5 -> f6 |
| 299 | + } |
| 300 | + |
| 301 | +.. graphviz:: |
| 302 | + :caption: 重构复杂脚本自动修正模式三 |
| 303 | + :align: center |
| 304 | + :name: g-project-rft-autofix-3 |
| 305 | + |
| 306 | + digraph G { |
| 307 | + node [shape=box, style=rounded, target="_top"] |
| 308 | + |
| 309 | + build [label="pyarmor build --autofix 3" |
| 310 | + style="filled,rounded" |
| 311 | + fillcolor="wheat"] |
| 312 | + join1 [shape=point] |
| 313 | + |
| 314 | + items [label="依次处理每一个脚本"] |
| 315 | + |
| 316 | + conf [label="工程属性\n存放在 .pyarmor/config 中"] |
| 317 | + |
| 318 | + rules [shape=plaintext |
| 319 | + label="工程的重构选项\n存放在 .pyarmor/config 中"] |
| 320 | + p1 [label="应用重构规则"] |
| 321 | + rft [label="尝试重构每一个脚本"] |
| 322 | + |
| 323 | + n1 [label="记录工程内部模块定义的类型\n合并所有内部类型的属性\n生成内部属性表"] |
| 324 | + n2 [label="记录所有的未知属性\n生成未知属性表"] |
| 325 | + |
| 326 | + autofix [shape=component |
| 327 | + style="filled" |
| 328 | + fillcolor="tan" |
| 329 | + label="生成重构规则,保存到\n.pyarmor/project/rft_autofix.rules\n所有内部属性名称都会进行重命名"] |
| 330 | + autolog [shape=box |
| 331 | + style="filled,rounded" |
| 332 | + fillcolor="tan" |
| 333 | + label="生成修正记录表\n.pyarmor/project/rft_autofix.3.org"] |
| 334 | + |
| 335 | + build -> join1 |
| 336 | + join1 -> conf [dir=none] |
| 337 | + join1 -> items [label="得到工程中的脚本列表"] |
| 338 | + items -> p1 |
| 339 | + rank=same { p1 -> rft } |
| 340 | + p1 -> rules [arrowtail=curve dir=back] |
| 341 | + rft -> n1 -> autofix |
| 342 | + rft -> n2 [tailport=e] |
| 343 | + n2 -> autolog |
| 344 | + |
| 345 | + m1 [label="浏览修正记录表\n根据修正记录表的内容\n人工生成重构规则"] |
| 346 | + autolog -> m1 |
| 347 | + m1 -> autofix [label="增加重构规则"] |
| 348 | + |
| 349 | + rebuild [style="filled,rounded" |
| 350 | + fillcolor="wheat" |
| 351 | + label="再次构建工程\npyarmor build --rft"] |
| 352 | + test [label="运行重构后的脚本\npython dist/foo.py"] |
| 353 | + fb [label="是否出现 AttributeError?"] |
| 354 | + |
| 355 | + autofix -> rebuild -> test -> fb |
| 356 | + fb -> m1 [label="出现错误"] |
| 357 | + } |
| 358 | + |
| 359 | +.. _project-build-mini: |
| 360 | + |
| 361 | +生成迷你型脚本 |
| 362 | +-------------- |
| 363 | + |
| 364 | +.. graphviz:: |
| 365 | + :caption: 生成迷你型脚本 |
| 366 | + :align: center |
| 367 | + :name: g-project-build-mini |
| 368 | + |
| 369 | + digraph G { |
| 370 | + node [shape=box, style=rounded, target="_top"] |
| 371 | + |
| 372 | + build [label="pyarmor build --mini" |
| 373 | + style="filled,rounded" |
| 374 | + fillcolor="wheat"] |
| 375 | + join1 [shape=point] |
| 376 | + |
| 377 | + items [label="依次处理每一个脚本"] |
| 378 | + conf [label="工程属性\n存放在 .pyarmor/config 中"] |
| 379 | + mini [label="生成迷你型加密脚本"] |
| 380 | + |
| 381 | + build -> join1 |
| 382 | + join1 -> conf [dir=none] |
| 383 | + join1 -> items [label="得到工程中的脚本列表"] |
| 384 | + items -> mini |
| 385 | + } |
0 commit comments