Run ardmk-init without dependancy if running quiet
This commit is contained in:
parent
55c149fb03
commit
2a4c2660be
1 changed files with 21 additions and 14 deletions
|
@ -20,7 +20,6 @@ See `armk-init --help` for CLI arguments
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
from clint.textui import prompt, validators, colored, puts
|
|
||||||
|
|
||||||
## Global Vars
|
## Global Vars
|
||||||
VERSION = "1.0"
|
VERSION = "1.0"
|
||||||
|
@ -56,6 +55,14 @@ PARSER.add_argument('-t', '--template', action='store_true',
|
||||||
help='create bare minimum Arduino source file')
|
help='create bare minimum Arduino source file')
|
||||||
ARGS = PARSER.parse_args()
|
ARGS = PARSER.parse_args()
|
||||||
|
|
||||||
|
try:
|
||||||
|
from clint.textui import prompt, validators
|
||||||
|
except ImportError:
|
||||||
|
if not ARGS.quiet:
|
||||||
|
print("Python module 'clint' is required for running prompted. Install the module or run with arguments only using --quiet")
|
||||||
|
quit()
|
||||||
|
|
||||||
|
|
||||||
def generate_makefile():
|
def generate_makefile():
|
||||||
"""
|
"""
|
||||||
Generate the Makefile content using prompts or parsed arguments
|
Generate the Makefile content using prompts or parsed arguments
|
||||||
|
@ -65,8 +72,8 @@ def generate_makefile():
|
||||||
|
|
||||||
# Basic
|
# Basic
|
||||||
if not ARGS.quiet:
|
if not ARGS.quiet:
|
||||||
puts(colored.cyan("Generating Arduino Ard-Makefile project in "
|
print("Generating Arduino Ard-Makefile project in "
|
||||||
+ os.path.abspath(ARGS.directory)))
|
+ os.path.abspath(ARGS.directory))
|
||||||
btag = prompt.query('Board tag?', default='uno')
|
btag = prompt.query('Board tag?', default='uno')
|
||||||
if btag != 'uno':
|
if btag != 'uno':
|
||||||
bsub = prompt.query('Board sub micro?', default='atmega328')
|
bsub = prompt.query('Board sub micro?', default='atmega328')
|
||||||
|
@ -188,9 +195,9 @@ def write_to_makefile(file_content, path):
|
||||||
Write the Makefile file
|
Write the Makefile file
|
||||||
"""
|
"""
|
||||||
makefile = open(path + "Makefile", 'w')
|
makefile = open(path + "Makefile", 'w')
|
||||||
puts(colored.cyan("Writing Makefile..."))
|
print("Writing Makefile...")
|
||||||
if ARGS.verbose:
|
if ARGS.verbose:
|
||||||
puts(colored.yellow(file_content))
|
print(file_content)
|
||||||
makefile.write(file_content)
|
makefile.write(file_content)
|
||||||
makefile.close()
|
makefile.close()
|
||||||
|
|
||||||
|
@ -198,17 +205,17 @@ def write_template(filename):
|
||||||
"""
|
"""
|
||||||
Write template Arduino .ino source
|
Write template Arduino .ino source
|
||||||
"""
|
"""
|
||||||
puts(colored.cyan("Writing " + os.path.abspath(filename) + ".ino..."))
|
print("Writing " + os.path.abspath(filename) + ".ino...")
|
||||||
if os.path.isfile(filename + '.ino'):
|
if os.path.isfile(filename + '.ino'):
|
||||||
if ARGS.quiet:
|
if ARGS.quiet:
|
||||||
puts(colored.red(filename + '.ino' + ' already exists! Stopping.'))
|
print(filename + '.ino' + ' already exists! Stopping.')
|
||||||
return
|
return
|
||||||
puts(colored.red(filename + '.ino' + ' already exists! Overwrite?'))
|
print(filename + '.ino' + ' already exists! Overwrite?')
|
||||||
if prompt.yn('Continue?', default='n'):
|
if prompt.yn('Continue?', default='n'):
|
||||||
return
|
return
|
||||||
src = open((filename + ".ino"), 'w')
|
src = open((filename + ".ino"), 'w')
|
||||||
if ARGS.verbose:
|
if ARGS.verbose:
|
||||||
puts(colored.yellow(ARD_TEMPLATE))
|
print(ARD_TEMPLATE)
|
||||||
src.write("/* Project: " + filename + " */\n" + ARD_TEMPLATE)
|
src.write("/* Project: " + filename + " */\n" + ARD_TEMPLATE)
|
||||||
src.close()
|
src.close()
|
||||||
|
|
||||||
|
@ -218,7 +225,7 @@ def check_create_folder(folder):
|
||||||
"""
|
"""
|
||||||
if folder and not folder == 'AUTO':
|
if folder and not folder == 'AUTO':
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
puts(colored.cyan(("Creating " + os.path.abspath(folder) + " folder")))
|
print("Creating " + os.path.abspath(folder) + " folder")
|
||||||
os.makedirs(folder)
|
os.makedirs(folder)
|
||||||
|
|
||||||
def check_define(define, user):
|
def check_define(define, user):
|
||||||
|
@ -241,13 +248,13 @@ if __name__ == '__main__':
|
||||||
os.chdir(ARGS.directory)
|
os.chdir(ARGS.directory)
|
||||||
if os.path.isfile('Makefile'):
|
if os.path.isfile('Makefile'):
|
||||||
if ARGS.quiet:
|
if ARGS.quiet:
|
||||||
puts(colored.red('Makefile in ' + os.path.abspath(ARGS.directory)
|
print('Makefile in ' + os.path.abspath(ARGS.directory)
|
||||||
+ ' already exists! Stopping.'))
|
+ ' already exists! Stopping.')
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
# Confirm with user if not quiet mode
|
# Confirm with user if not quiet mode
|
||||||
puts(colored.red('Makefile in ' + os.path.abspath(ARGS.directory)
|
print('Makefile in ' + os.path.abspath(ARGS.directory)
|
||||||
+ ' already exists! Overwrite?'))
|
+ ' already exists! Overwrite?')
|
||||||
if prompt.yn('Continue?', default='n'):
|
if prompt.yn('Continue?', default='n'):
|
||||||
quit()
|
quit()
|
||||||
# Run it
|
# Run it
|
||||||
|
|
Loading…
Reference in a new issue