File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -174,15 +174,15 @@ Some utility methods are provided and are still in development:
174174
175175# # Convenience and scaffolding methods
176176
177- # ## create_project(PROJECT_NAME , PATH)
177+ # ## create_sketch(SKETCH_NAME , PATH)
178178
179179Will create a new Python file (`.py` ) with the specified name at the provided path.
180180Example:
181181
182182```Python
183- create_project (' my_arduino_sketch' )
184- create_project (' my_arduino_sketch' , ' tmp' )
185- create_project (' main' )
183+ create_sketch (' my_arduino_sketch' )
184+ create_sketch (' my_arduino_sketch' , ' tmp' )
185+ create_sketch (' main' )
186186```
187187
188188If the destination `.py` file exists, a timestamp in _microseconds_ will be appended to the name.
Original file line number Diff line number Diff line change @@ -82,21 +82,23 @@ def delay(_ms):
8282
8383
8484# HELPERS
85- def create_new_sketch (sketch_name = None , path = '.' ):
85+ def create_sketch (sketch_name = None , path = '.' , overwrite = False ):
8686
87+ if sketch_name is None :
88+ sketch_name = 'main'
8789 new_sketch_path = f'{ path } /{ sketch_name } .py'
8890 try :
89- open (new_sketch_path , 'x' )
91+ open (new_sketch_path , 'r' )
92+ if not overwrite :
93+ sketch_name = f'{ sketch_name } _{ ticks_us ()} '
9094 except OSError :
91- sketch_name = f' { sketch_name } _ { ticks_us () } '
95+ pass
9296
93- if sketch_name is None :
94- sketch_name = f'main_{ ticks_us ()} .py'
9597 template_path = '/' .join (__file__ .split ('/' )[:- 1 ]) + '/template.py'
9698 template_sketch = open (template_path , 'r' )
9799 new_sketch_path = f'{ path } /{ sketch_name } .py'
98100
99- with open (f' { path } / { sketch_name } .py' , 'w' ) as f :
101+ with open (new_sketch_path , 'w' ) as f :
100102 sketch_line = None
101103 while sketch_line is not '' :
102104 sketch_line = template_sketch .readline ()
You can’t perform that action at this time.
0 commit comments