Add string validation for projectname

Former-commit-id: ad443beb5b
pull/1161/head
Dakota Benjamin 2017-02-09 18:57:24 -05:00
rodzic f9d2d416e9
commit 0622690688
2 zmienionych plików z 19 dodań i 3 usunięć

Wyświetl plik

@ -11,6 +11,12 @@ with open(context.settings_path) as stream:
datamap = yaml.safe_load(stream)
defaultSettings = datamap['settings']
def alphanumeric_string(string):
import re
if re.match('^[a-zA-Z0-9]+$', str) is None:
msg = '{0} is not a valid name. Must use alphanumeric characters.'.format(string)
raise argparse.ArgumentTypeError(msg)
return string
class RerunFrom(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
@ -30,6 +36,11 @@ def config():
help='Path to the project to process',
default=defaultSettings[0]['project_path'])
parser.add_argument('name',
metavar='<string>',
type=alphanumeric_string,
help='Name of Project (i.e subdirectory of projects folder)')
parser.add_argument('--resize-to', # currently doesn't support 'orig'
metavar='<integer>',
default=2400,

11
run.py
Wyświetl plik

@ -13,7 +13,8 @@ from scripts.odm_app import ODMApp
def usage():
log.ODM_ERROR('USAGE: %s --project-path [project_path]' % sys.argv[0])
log.ODM_ERROR('You must specify a project name:')
log.ODM_ERROR('USAGE: %s [project name]' % sys.argv[0])
log.ODM_ERROR('OpenDroneMap app finished - %s' % system.now())
sys.exit(0)
@ -24,11 +25,15 @@ if __name__ == '__main__':
args = config.config()
# Check that args.name is a valid string
proj_dir = io.join_paths(args.project_path, args.name)
# Force to provide the images path
if args.project_path is None:
usage()
elif not io.dir_exists(args.project_path):
log.ODM_WARNING('Directory %s does not exist. Creating it now.' % args.project_path)
if not io.dir_exists(args.name):
log.ODM_WARNING('Directory %s does not exist. Creating it now.' % args.name)
system.mkdir_p(os.path.abspath(args.project_path))
#If user asks to rerun everything, delete all of the existing progress directories.