-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve command line arguments #632
Changes from all commits
a4d7554
231125e
ad9a215
ee2fc63
979ee4b
fa7b458
06543f8
a53940d
ce6dcba
49c5789
9a473ad
ab7b940
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,20 @@ class MeshroomApp(QApplication): | |
""" Meshroom UI Application. """ | ||
def __init__(self, args): | ||
QtArgs = [args[0], '-style', 'fusion'] + args[1:] # force Fusion style by default | ||
|
||
parser = argparse.ArgumentParser(prog=args[0], description='Launch Meshroom UI.', add_help=True) | ||
|
||
parser.add_argument('project', metavar='PROJECT', type=str, nargs='?', | ||
help='Meshroom project file (e.g. myProject.mg) or folder with images to reconstruct.') | ||
parser.add_argument('-i', '--import', metavar='IMAGES/FOLDERS', type=str, nargs='*', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't now the arguments a little bit too redundant? |
||
help='Import images or folder with images to reconstruct.') | ||
parser.add_argument('-I', '--importRecursive', metavar='FOLDERS', type=str, nargs='*', | ||
help='Import images to reconstruct from specified folder and sub-folders.') | ||
parser.add_argument('-p', '--pipeline', metavar='MESHROOM_FILE', type=str, required=False, | ||
help='Override the default Meshroom pipeline with this external graph.') | ||
|
||
args = parser.parse_args(args[1:]) | ||
|
||
super(MeshroomApp, self).__init__(QtArgs) | ||
|
||
self.setOrganizationName('AliceVision') | ||
|
@@ -105,12 +119,29 @@ def __init__(self, args): | |
# request any potential computation to stop on exit | ||
self.aboutToQuit.connect(r.stopChildThreads) | ||
|
||
parser = argparse.ArgumentParser(prog=args[0], description='Launch Meshroom UI.') | ||
parser.add_argument('--project', metavar='MESHROOM_FILE', type=str, required=False, | ||
help='Meshroom project file (e.g. myProject.mg).') | ||
args = parser.parse_args(args[1:]) | ||
if args.pipeline: | ||
# the pipeline from the command line has the priority | ||
r.setDefaultPipeline(args.pipeline) | ||
else: | ||
# consider the environment variable | ||
defaultPipeline = os.environ.get("MESHROOM_DEFAULT_PIPELINE", "") | ||
if defaultPipeline: | ||
r.setDefaultPipeline(args.pipeline) | ||
|
||
if args.project and not os.path.isfile(args.project): | ||
raise RuntimeError( | ||
"Meshroom Command Line Error: 'PROJECT' argument should be a Meshroom project file (.mg).\n" | ||
"Invalid value: '{}'".format(args.project)) | ||
|
||
if args.project: | ||
r.loadUrl(QUrl.fromLocalFile(args.project)) | ||
r.load(args.project) | ||
|
||
# import is a python keyword, so we have to access the attribute by a string | ||
if getattr(args, "import", None): | ||
r.importImagesFromFolder(getattr(args, "import"), recursive=False) | ||
|
||
if args.importRecursive: | ||
r.importImagesFromFolder(args.importRecursive, recursive=True) | ||
|
||
self.engine.load(os.path.normpath(url)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just asking,
findNode(node)
can fail in the same way asnodesByType(node)
? Shall we manage the error?Also, very minor thing, I'd put the print after the setting is done so it is not print in case of failure (hopefully
findNode(node)
orattribute(param)
will print or raise some kind of error?)In case, the same for the previous
nodesByType(node)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findNode is looking for one specific node and fails with an explicit message if it doesn't find it.
nodesByType looks for all nodes of a specific type and can return an empty list without error (that's why there is a specific check to provide an error message).
I put the print before so it's more visible in the error message :s, the last NODE.PARAM is printed and then you have the error message saying that it doesn't find PARAM for instance.