Skip to content

Commit 2a4c266

Browse files
committed
Run ardmk-init without dependancy if running quiet
1 parent 55c149f commit 2a4c266

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

bin/ardmk-init

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ See `armk-init --help` for CLI arguments
2020
from __future__ import print_function
2121
import os
2222
import argparse
23-
from clint.textui import prompt, validators, colored, puts
2423

2524
## Global Vars
2625
VERSION = "1.0"
@@ -56,6 +55,14 @@ PARSER.add_argument('-t', '--template', action='store_true',
5655
help='create bare minimum Arduino source file')
5756
ARGS = PARSER.parse_args()
5857

58+
try:
59+
from clint.textui import prompt, validators
60+
except ImportError:
61+
if not ARGS.quiet:
62+
print("Python module 'clint' is required for running prompted. Install the module or run with arguments only using --quiet")
63+
quit()
64+
65+
5966
def generate_makefile():
6067
"""
6168
Generate the Makefile content using prompts or parsed arguments
@@ -65,8 +72,8 @@ def generate_makefile():
6572

6673
# Basic
6774
if not ARGS.quiet:
68-
puts(colored.cyan("Generating Arduino Ard-Makefile project in "
69-
+ os.path.abspath(ARGS.directory)))
75+
print("Generating Arduino Ard-Makefile project in "
76+
+ os.path.abspath(ARGS.directory))
7077
btag = prompt.query('Board tag?', default='uno')
7178
if btag != 'uno':
7279
bsub = prompt.query('Board sub micro?', default='atmega328')
@@ -188,27 +195,27 @@ def write_to_makefile(file_content, path):
188195
Write the Makefile file
189196
"""
190197
makefile = open(path + "Makefile", 'w')
191-
puts(colored.cyan("Writing Makefile..."))
198+
print("Writing Makefile...")
192199
if ARGS.verbose:
193-
puts(colored.yellow(file_content))
200+
print(file_content)
194201
makefile.write(file_content)
195202
makefile.close()
196203

197204
def write_template(filename):
198205
"""
199206
Write template Arduino .ino source
200207
"""
201-
puts(colored.cyan("Writing " + os.path.abspath(filename) + ".ino..."))
208+
print("Writing " + os.path.abspath(filename) + ".ino...")
202209
if os.path.isfile(filename + '.ino'):
203210
if ARGS.quiet:
204-
puts(colored.red(filename + '.ino' + ' already exists! Stopping.'))
211+
print(filename + '.ino' + ' already exists! Stopping.')
205212
return
206-
puts(colored.red(filename + '.ino' + ' already exists! Overwrite?'))
213+
print(filename + '.ino' + ' already exists! Overwrite?')
207214
if prompt.yn('Continue?', default='n'):
208215
return
209216
src = open((filename + ".ino"), 'w')
210217
if ARGS.verbose:
211-
puts(colored.yellow(ARD_TEMPLATE))
218+
print(ARD_TEMPLATE)
212219
src.write("/* Project: " + filename + " */\n" + ARD_TEMPLATE)
213220
src.close()
214221

@@ -218,7 +225,7 @@ def check_create_folder(folder):
218225
"""
219226
if folder and not folder == 'AUTO':
220227
if not os.path.exists(folder):
221-
puts(colored.cyan(("Creating " + os.path.abspath(folder) + " folder")))
228+
print("Creating " + os.path.abspath(folder) + " folder")
222229
os.makedirs(folder)
223230

224231
def check_define(define, user):
@@ -241,13 +248,13 @@ if __name__ == '__main__':
241248
os.chdir(ARGS.directory)
242249
if os.path.isfile('Makefile'):
243250
if ARGS.quiet:
244-
puts(colored.red('Makefile in ' + os.path.abspath(ARGS.directory)
245-
+ ' already exists! Stopping.'))
251+
print('Makefile in ' + os.path.abspath(ARGS.directory)
252+
+ ' already exists! Stopping.')
246253
quit()
247254

248255
# Confirm with user if not quiet mode
249-
puts(colored.red('Makefile in ' + os.path.abspath(ARGS.directory)
250-
+ ' already exists! Overwrite?'))
256+
print('Makefile in ' + os.path.abspath(ARGS.directory)
257+
+ ' already exists! Overwrite?')
251258
if prompt.yn('Continue?', default='n'):
252259
quit()
253260
# Run it

0 commit comments

Comments
 (0)