-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.py
82 lines (60 loc) · 3.17 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'''
Python script to implement terminal command functionality
To test the laser gcode for example
python3 cli.py -D test.gcode --laser --debug-laser gerber_files/mirrored_and_offseted.gbr
'''
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from main import Settings, main
from default_settings import default_settings_dict
from typing import Optional
def addArg(name: str, help_str: str, var_type, one_letter: Optional[str]=None) -> None:
'''
implements parser.add_argument() easily
'''
global parser
global default_settings_dict
if '-' in name:
raise ValueError('Please enter the python name (with _ not -)')
if '_' in name:
cli_name = name.replace('_', '-')
else:
cli_name = name
if var_type != bool:
if one_letter:
parser.add_argument(f'-{one_letter}', f'--{cli_name}', type=var_type, default=default_settings_dict[name], help=help_str)
else:
parser.add_argument(f'--{cli_name}', type=var_type, default=default_settings_dict[name], help=help_str)
else:
if one_letter:
parser.add_argument(f'-{one_letter}', f'--{cli_name}', action="store_true", default=default_settings_dict[name], help=help_str)
else:
parser.add_argument(f'--{cli_name}', action="store_true", default=default_settings_dict[name], help=help_str)
return parser
if __name__ == '__main__':
# Initiating Settings object
settings = Settings()
### Creating the CLI argument parser
parser = ArgumentParser(description="Generates Custom Gcode Required by my PCB Manufacturing Machine :)",
formatter_class=ArgumentDefaultsHelpFormatter)
### Adding the positional arguments
parser.add_argument('src', help="Source Gerber file to be converted to Gcode\n")
### Adding keyword Arguments
addArg('dest', "Destination Gcode file", str, 'D')
addArg('mirrored', "Mirror Given Srouce Gerber file. Used for traces of DIP components", bool, 'M')
addArg('rotated', "Rotate 90degrees Given Srouce Gerber file. Used for traces of DIP components", bool, 'R')
addArg('x_offset', "Value PCB offseted from X axis", int)
addArg('y_offset', "Value PCB offseted from Y axis", int)
addArg('all_gcode', "Creates a Gcode file with hole drilling gcode, ink laying gcode and laser drawing gcode", bool, 'ALL')
addArg('holes', "Adds hole drilling gcode to Gcode file", bool)
addArg('ink', "Adds ink laying gcode to Gcode file", bool)
addArg('laser', "Adds laser drawing gcode to Gcode file", bool)
addArg('include_edge_cuts', "Include Edge cuts in laser marking process", bool)
addArg('laser_passes', "Number of passes for laser marking Gcode", int)
addArg('debug', "Shows Simulation of the PCB laser trace coordinates as well as other debug Info.", bool)
addArg('dont_export_gbr', "Doesn't allow exporting of the mirrored_and_offseted gerber file", bool)
addArg('new_gbr_name', "The name of the newly created Gerber File after mirroring and offsetting", str)
### Extracting User inputs!
# Getting arguments
settings.settings_dict.update(vars(parser.parse_args()))
### Executing the Program!
main(settings)