CLI Usage

In potc, cli is provided to quickly generate python code. For example, you can translate an object with potc trans command. Firstly, here is the content of python source file data.py

1
2
3
4
5
6
7
8
import math

v_a = [1, 'kdfgjs', None, math.pi]
v_b = {
    'a': v_a,
    'b': (3, 4, 'dfg'),
    0: {'a': 3, 'b': None, 'c': math.e}
}

Translation of Single Object

Based on data.py, we can translate v_a from data.py by this command

1
potc trans data.v_a

The output should be

1
[1, 'kdfgjs', None, math.pi]

Also, if you need to take a look at the full information of this translation, you can use -I option to display them, like this

1
potc trans data.v_b -I

The output (including information) should be

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Object Information:
Module : data
Name : v_b
Type : dict

Import Statements:
import math

Expression:
{'a': [1, 'kdfgjs', None, math.pi], 'b': (3, 4, 'dfg'), 0: {'a': 3, 'b': None, 'c': math.e}}

Export Multiple Objects

In further cases, we may need to directly dump a runnable python source code and then maybe execute it. You can dump the variables from data.py by this command

1
potc export -v 'data.v_*'

The dumped code should be

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import math

__all__ = ['v_a', 'v_b']
v_a = [1, 'kdfgjs', None, math.pi]
v_b = {
    'a': [1, 'kdfgjs', None, math.pi],
    'b': (3, 4, 'dfg'),
    0: {
        'a': 3,
        'b': None,
        'c': math.e
    }
}

Besides, you can use your self-defined rules to change the dumping result, like this

1
potc export -v 'data.v_*' -r plugins.dict.potc_dict.plugin.__rules__

The new dumped code should be

1