ardmk-init runs without prompt by default, cli arg added to avoid clint dependency
This commit is contained in:
parent
78d11c6678
commit
d874c59103
2 changed files with 42 additions and 29 deletions
12
ardmk-init.1
12
ardmk-init.1
|
@ -1,4 +1,4 @@
|
||||||
.TH ARDMK-INIT "1" "Oct 2017" "ardmk-init" "Arduino Makefile Generator"
|
.TH ARDMK-INIT "1" "Nov 2017" "ardmk-init" "Arduino Makefile Generator"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
ardmk-init - Generate Arduino Makefile environments
|
ardmk-init - Generate Arduino Makefile environments
|
||||||
|
@ -29,8 +29,8 @@ Monitor port.
|
||||||
.B \-n, \-\-name
|
.B \-n, \-\-name
|
||||||
Project name.
|
Project name.
|
||||||
|
|
||||||
.B \-q, \-\-quiet
|
.B \-\-cli
|
||||||
Run quiet without user prompts.
|
Run with user prompts rather than arguments.
|
||||||
|
|
||||||
.B \-p, \-\-project
|
.B \-p, \-\-project
|
||||||
Create boilerplate project with src, lib and bin folder structure.
|
Create boilerplate project with src, lib and bin folder structure.
|
||||||
|
@ -42,11 +42,11 @@ Create bare minimum Arduino source file.
|
||||||
Creates a Makefile and project tree structure from templates.
|
Creates a Makefile and project tree structure from templates.
|
||||||
|
|
||||||
.SH EXAMPLE
|
.SH EXAMPLE
|
||||||
ardmk-init -qb uno # create Arduino uno Makefile quietly
|
ardmk-init -b uno # create Arduino uno Makefile
|
||||||
.PP
|
.PP
|
||||||
ardmk-init # run with user prompts
|
ardmk-init --cli # run with user prompts
|
||||||
.PP
|
.PP
|
||||||
ardmk-init --board uno --project --template --name my-project --quiet # create Arduino uno project and template with name "my-project"
|
ardmk-init --board uno --project --template --name my-project # create Arduino uno project and template with name "my-project"
|
||||||
|
|
||||||
.SH BUGS
|
.SH BUGS
|
||||||
Problems may reported on the github project page at:
|
Problems may reported on the github project page at:
|
||||||
|
|
|
@ -7,12 +7,12 @@ for use with Arduino-mk. Addionally, it can be used to create a template
|
||||||
Arduino source file and a traditional boilerplate project file structure.
|
Arduino source file and a traditional boilerplate project file structure.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
* Run prompted within current working directory: `ardmk-init`
|
* Run prompted within current working directory (requires Clint): `ardmk-init --cli`
|
||||||
* Create Arduino Uno Makefile (useful within a library example): `ardmk-init -qb uno`
|
* Create Arduino Uno Makefile (useful within a library example): `ardmk-init -b uno`
|
||||||
* Create boilerplate Arduino Uno project in current working directory of same
|
* Create boilerplate Arduino Uno project in current working directory of same
|
||||||
name: `ardmk-init -b uno --quiet --project`
|
name: `ardmk-init -b uno --project`
|
||||||
* Create Arduino-mk nano Makefile in current working directory with template .ino:
|
* Create Arduino-mk nano Makefile in current working directory with template .ino:
|
||||||
`ardmk-init -b nano -u atmega328 -qtn my-project`
|
`ardmk-init -b nano -u atmega328 -tn my-project`
|
||||||
|
|
||||||
See `armk-init --help` for CLI arguments
|
See `armk-init --help` for CLI arguments
|
||||||
"""
|
"""
|
||||||
|
@ -22,7 +22,7 @@ import os
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
## Global Vars
|
## Global Vars
|
||||||
VERSION = "1.0"
|
VERSION = "1.1"
|
||||||
ARD_TEMPLATE = "\n\
|
ARD_TEMPLATE = "\n\
|
||||||
#include <Arduino.h>\n\
|
#include <Arduino.h>\n\
|
||||||
#include <Wire.h>\n\
|
#include <Wire.h>\n\
|
||||||
|
@ -36,30 +36,32 @@ void loop() {\n\
|
||||||
"
|
"
|
||||||
|
|
||||||
## Command Parser
|
## Command Parser
|
||||||
PARSER = argparse.ArgumentParser(description='Arduino Makefile and boilerplate project generator.\
|
PARSER = argparse.ArgumentParser(prog='ardmk-init',
|
||||||
|
description='Arduino Makefile and boilerplate project generator.\
|
||||||
For use with Ard-Makefile: https://github.com/sudar/Arduino-Makefile.\
|
For use with Ard-Makefile: https://github.com/sudar/Arduino-Makefile.\
|
||||||
Script created by John Whittington https://github.com/tuna-f1sh 2017\
|
Script created by John Whittington https://github.com/tuna-f1sh 2017\
|
||||||
\n\nVersion: ' + VERSION, usage='ardmk-init # prompted CLI, see --help for more.')
|
\n\nVersion: ' + VERSION)
|
||||||
PARSER.add_argument('-v', '--verbose', action='store_true',
|
PARSER.add_argument('-v', '--verbose', action='store_true',
|
||||||
help="print file contents during creation")
|
help="print file contents during creation")
|
||||||
PARSER.add_argument('-d', '--directory', default=os.getcwd(), help='directory to run generator')
|
PARSER.add_argument('-d', '--directory', default=os.getcwd(), help='directory to run generator, default cwd')
|
||||||
PARSER.add_argument('-b', '--board', default='uno', help='board tag')
|
PARSER.add_argument('-b', '--board', default='uno', help='board tag')
|
||||||
PARSER.add_argument('-u', '--micro', default='AUTO', help='microcontroller on board')
|
PARSER.add_argument('-u', '--micro', default='AUTO', help='microcontroller on board')
|
||||||
PARSER.add_argument('-f', '--freq', default='AUTO', help='clock frequency')
|
PARSER.add_argument('-f', '--freq', default='AUTO', help='clock frequency')
|
||||||
PARSER.add_argument('-p', '--port', default='AUTO', help='monitor port')
|
PARSER.add_argument('-p', '--port', default='AUTO', help='monitor port')
|
||||||
PARSER.add_argument('-n', '--name', default=os.path.basename(os.getcwd()), help='project name')
|
PARSER.add_argument('-n', '--name', default=os.path.basename(os.getcwd()), help='project name')
|
||||||
PARSER.add_argument('-q', '--quiet', action='store_true', help='run quiet without user prompts')
|
PARSER.add_argument('--cli', action='store_true', help='run with user prompts (requires "Clint" module), rather than args')
|
||||||
PARSER.add_argument('-P', '--project', action='store_true',
|
PARSER.add_argument('-P', '--project', action='store_true',
|
||||||
help='create boilerplate project with src, lib and bin folder structure')
|
help='create boilerplate project with src, lib and bin folder structure')
|
||||||
PARSER.add_argument('-t', '--template', action='store_true',
|
PARSER.add_argument('-t', '--template', action='store_true',
|
||||||
help='create bare minimum Arduino source file')
|
help='create bare minimum Arduino source file')
|
||||||
|
PARSER.add_argument('-V', '--version', action='version', version='%(prog)s '+ VERSION)
|
||||||
ARGS = PARSER.parse_args()
|
ARGS = PARSER.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from clint.textui import prompt, validators
|
from clint.textui import prompt, validators
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if not ARGS.quiet:
|
if ARGS.cli:
|
||||||
print("Python module 'clint' is required for running prompted. Install the module or run with arguments only using --quiet")
|
print("Python module 'clint' is required for running prompted. Install the module or run with arguments only")
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ def generate_makefile():
|
||||||
file_content = "# Generated by ard-make version " + VERSION + "\n\n"
|
file_content = "# Generated by ard-make version " + VERSION + "\n\n"
|
||||||
|
|
||||||
# Basic
|
# Basic
|
||||||
if not ARGS.quiet:
|
if ARGS.cli:
|
||||||
print("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')
|
||||||
|
@ -94,10 +96,10 @@ def generate_makefile():
|
||||||
file_content += check_define('MONITOR_PORT', monitor_port)
|
file_content += check_define('MONITOR_PORT', monitor_port)
|
||||||
|
|
||||||
# Extended
|
# Extended
|
||||||
if not ARGS.quiet:
|
if ARGS.cli:
|
||||||
if not prompt.yn('Extended options?', default='n'):
|
if not prompt.yn('Extended options?', default='n'):
|
||||||
if not prompt.yn('Define local folders?', default='n'):
|
if not prompt.yn('Define local folders?', default='n'):
|
||||||
src_dir = prompt.query('Sources folder (Makefile will be created here)?',\
|
src_dir = prompt.query('Sources folder (Makefile will be created here)?',
|
||||||
default='', validators=[])
|
default='', validators=[])
|
||||||
userlibs = prompt.query('Library folder (will create if does not exist) - AUTO is Sketchbook directory?',
|
userlibs = prompt.query('Library folder (will create if does not exist) - AUTO is Sketchbook directory?',
|
||||||
default='AUTO', validators=[])
|
default='AUTO', validators=[])
|
||||||
|
@ -171,9 +173,9 @@ def generate_makefile():
|
||||||
file_content += check_define('TARGET', ARGS.name)
|
file_content += check_define('TARGET', ARGS.name)
|
||||||
|
|
||||||
if not "ARDMK_DIR" in os.environ:
|
if not "ARDMK_DIR" in os.environ:
|
||||||
if ARGS.quiet:
|
if not ARGS.cli:
|
||||||
puts(colored.magenta('Warning: ARDMK_DIR environment variable not defined. \
|
print("Warning: ARDMK_DIR environment variable not defined. \
|
||||||
Must be defined for Makefile to work'))
|
Must be defined for Makefile to work")
|
||||||
else:
|
else:
|
||||||
ardmk = prompt.query('Arduino Makefile path?',
|
ardmk = prompt.query('Arduino Makefile path?',
|
||||||
default='/usr/share/arduino',
|
default='/usr/share/arduino',
|
||||||
|
@ -207,7 +209,7 @@ def write_template(filename):
|
||||||
"""
|
"""
|
||||||
print("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 not ARGS.cli:
|
||||||
print(filename + '.ino' + ' already exists! Stopping.')
|
print(filename + '.ino' + ' already exists! Stopping.')
|
||||||
return
|
return
|
||||||
print(filename + '.ino' + ' already exists! Overwrite?')
|
print(filename + '.ino' + ' already exists! Overwrite?')
|
||||||
|
@ -241,15 +243,26 @@ def check_define(define, user):
|
||||||
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
def check_args():
|
||||||
|
"""
|
||||||
|
Check input args will work with Makefile
|
||||||
|
"""
|
||||||
|
# Micro should be defined for non uno boards
|
||||||
|
if ARGS.board != 'uno' and ARGS.micro == 'AUTO':
|
||||||
|
print('\n!!! Warning: --micro should be defined and not left AUTO for non-Uno boards\n')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Create directory if not exist
|
# Create directory if not exist
|
||||||
check_create_folder(ARGS.directory)
|
check_create_folder(ARGS.directory)
|
||||||
|
# Check input args
|
||||||
|
check_args()
|
||||||
# Change to dir so all commands are run relative
|
# Change to dir so all commands are run relative
|
||||||
os.chdir(ARGS.directory)
|
os.chdir(ARGS.directory)
|
||||||
if os.path.isfile('Makefile'):
|
if os.path.isfile('Makefile'):
|
||||||
if ARGS.quiet:
|
if not ARGS.cli:
|
||||||
print('Makefile in ' + os.path.abspath(ARGS.directory)
|
print('Makefile in ' + os.path.abspath(ARGS.directory)
|
||||||
+ ' already exists! Stopping.')
|
+ ' already exists! Please remove before generating. Stopping.')
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
# Confirm with user if not quiet mode
|
# Confirm with user if not quiet mode
|
||||||
|
|
Loading…
Reference in a new issue