Bug 1302765 - Allow `./mach taskgraph .. --parameters P` to take a URL; r?dustin Bug-1302765
authorHammad Akhtar <hammad13060@iiitd.ac.in>
Wed, 23 Nov 2016 12:30:28 +0530
branchBug-1302765
changeset 900371 0744c17e199f7de7574fa43b19658b6ac6d09105
parent 899661 1a3194836cb4c3da6ba3a9742a2d25cf26669b55
child 900372 7ae2f371ba11b48c9d994ce320c053bad92363be
push id156338
push userhammad13060@iiitd.ac.in
push dateWed, 23 Nov 2016 07:25:02 +0000
treeherdertry@66ed58f2d013 [default view] [failures only]
reviewersdustin
bugs1302765
milestone53.0a1
Bug 1302765 - Allow `./mach taskgraph .. --parameters P` to take a URL; r?dustin MozReview-Commit-ID: I29Plh4OymR
taskcluster/mach_commands.py
taskcluster/taskgraph/parameters.py
--- a/taskcluster/mach_commands.py
+++ b/taskcluster/mach_commands.py
@@ -38,26 +38,28 @@ class ShowTaskGraphSubCommand(SubCommand
             CommandArgument('--verbose', '-v', action="store_true",
                             help="include debug-level logging output"),
             CommandArgument('--json', '-J', action="store_const",
                             dest="format", const="json",
                             help="Output task graph as a JSON object"),
             CommandArgument('--labels', '-L', action="store_const",
                             dest="format", const="labels",
                             help="Output the label for each task in the task graph (default)"),
-            CommandArgument('--parameters', '-p', required=True,
+            CommandArgument('--parameters', '-p', default=False,
                             help="parameters file (.yml or .json; see "
                                  "`taskcluster/docs/parameters.rst`)`"),
             CommandArgument('--no-optimize', dest="optimize", action="store_false",
                             default="true",
                             help="do not remove tasks from the graph that are found in the "
                             "index (a.k.a. optimize the graph)"),
             CommandArgument('--tasks-regex', '--tasks', default=None,
                             help="only return tasks with labels matching this regular "
-                            "expression.")
+                            "expression."),
+            CommandArgument("--task-id", "--parameters-from-task", default=None,
+                            help="generates taskgraph using parameters of given task-id.")
 
         ]
         for arg in args:
             after = arg(after)
         return after
 
 
 @CommandProvider
--- a/taskcluster/taskgraph/parameters.py
+++ b/taskcluster/taskgraph/parameters.py
@@ -56,18 +56,32 @@ class Parameters(ReadOnlyDict):
         except KeyError:
             raise KeyError("taskgraph parameter {!r} not found".format(k))
 
 
 def load_parameters_file(options):
     """
     Load parameters from the --parameters option
     """
+    import urllib
+
+    url_prefix = "https://public-artifacts.taskcluster.net/";
+    url_postfix = "/0/public/parameters.yml"
+
     filename = options['parameters']
-    if not filename:
-        return Parameters()
-    with open(filename) as f:
-        if filename.endswith('.yml'):
-            return Parameters(**yaml.safe_load(f))
-        elif filename.endswith('.json'):
-            return Parameters(**json.load(f))
-        else:
-            raise TypeError("Parameters file `{}` is not JSON or YAML".format(filename))
+    task_id = options['task_id']
+
+    if not filename and not task_id:
+        return parameters()
+    elif not filename:
+        filename = url_prefix + task_id + url_postfix
+
+    if filename.startswith(url_prefix):
+        f = urllib.urlopen(filename)
+    else:
+        f = open(filename)
+
+    if filename.endswith('.yml'):
+        return Parameters(**yaml.safe_load(f))
+    elif filename.endswith('.json'):
+        return Parameters(**json.load(f))
+    else:
+        raise TypeError("Parameters file `{}` is not JSON or YAML".format(filename))