Bug 1561571 - Make backfill action's add_args_to_command reusable and add support for string cmd parts, r=tomprince.
authorBob Clary <bclary@bclary.com>
Fri, 05 Jul 2019 18:40:00 +0000
changeset 541142 4ea815152fd7e5d353cfdaebe21ae6840dc69900
parent 541141 1373ded9ebd53354a69d8637f4c34b3abe89df19
child 541143 0ec05244de2d0ea003a49cb9a0d7c29c617e9ba0
push id11533
push userarchaeopteryx@coole-files.de
push dateMon, 08 Jul 2019 18:18:03 +0000
treeherdermozilla-beta@f4452e031aed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstomprince
bugs1561571
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1561571 - Make backfill action's add_args_to_command reusable and add support for string cmd parts, r=tomprince. Differential Revision: https://phabricator.services.mozilla.com/D36012
taskcluster/taskgraph/actions/backfill.py
taskcluster/taskgraph/actions/util.py
--- a/taskcluster/taskgraph/actions/backfill.py
+++ b/taskcluster/taskgraph/actions/backfill.py
@@ -8,17 +8,17 @@ from __future__ import absolute_import, 
 
 import json
 import logging
 
 import requests
 from requests.exceptions import HTTPError
 
 from .registry import register_callback_action
-from .util import create_tasks, combine_task_graph_files
+from .util import create_tasks, combine_task_graph_files, add_args_to_command
 from taskgraph.util.taskcluster import get_artifact_from_index
 from taskgraph.util.taskgraph import find_decision_task
 from taskgraph.taskgraph import TaskGraph
 from taskgraph.util import taskcluster
 
 PUSHLOG_TMPL = '{}/json-pushes?version=2&startID={}&endID={}'
 INDEX_TMPL = 'gecko.v2.{}.pushlog-id.{}.decision'
 
@@ -233,34 +233,8 @@ def remove_args_from_command(cmd_parts, 
         cmd_parts.remove(cmd_parts[idx])
         idx -= 1
 
     if cmd_type == 'dict':
         cmd_parts = [{'task-reference': ' '.join(cmd_parts)}]
     elif cmd_type == 'subarray':
         cmd_parts = [cmd_parts]
     return cmd_parts
-
-
-def add_args_to_command(cmd_parts, extra_args=[]):
-    """
-        Add custom command line args to a given command.
-        args:
-          cmd_parts: the raw command as seen by taskcluster
-          extra_args: array of args we want to add
-    """
-    cmd_type = 'default'
-    if len(cmd_parts) == 1 and isinstance(cmd_parts[0], dict):
-        # windows has single cmd part as dict: 'task-reference', with long string
-        cmd_parts = cmd_parts[0]['task-reference'].split(' ')
-        cmd_type = 'dict'
-    elif len(cmd_parts) == 1 and isinstance(cmd_parts[0], list):
-        # osx has an single value array with an array inside
-        cmd_parts = cmd_parts[0]
-        cmd_type = 'subarray'
-
-    cmd_parts.extend(extra_args)
-
-    if cmd_type == 'dict':
-        cmd_parts = [{'task-reference': ' '.join(cmd_parts)}]
-    elif cmd_type == 'subarray':
-        cmd_parts = [cmd_parts]
-    return cmd_parts
--- a/taskcluster/taskgraph/actions/util.py
+++ b/taskcluster/taskgraph/actions/util.py
@@ -229,8 +229,41 @@ def relativize_datestamps(task_def):
                 diff = value - base
                 return {'relative-datestamp': '{} seconds'.format(int(diff.total_seconds()))}
         if isinstance(value, list):
             return [recurse(e) for e in value]
         if isinstance(value, dict):
             return {k: recurse(v) for k, v in value.items()}
         return value
     return recurse(task_def)
+
+
+def add_args_to_command(cmd_parts, extra_args=[]):
+    """
+        Add custom command line args to a given command.
+        args:
+          cmd_parts: the raw command as seen by taskcluster
+          extra_args: array of args we want to add
+    """
+    cmd_type = 'default'
+    if len(cmd_parts) == 1 and isinstance(cmd_parts[0], dict):
+        # windows has single cmd part as dict: 'task-reference', with long string
+        cmd_parts = cmd_parts[0]['task-reference'].split(' ')
+        cmd_type = 'dict'
+    elif len(cmd_parts) == 1 and (isinstance(cmd_parts[0], unicode) or
+                                  isinstance(cmd_parts[0], str)):
+        # windows has single cmd part as a long string
+        cmd_parts = cmd_parts[0].split(' ')
+        cmd_type = 'unicode'
+    elif len(cmd_parts) == 1 and isinstance(cmd_parts[0], list):
+        # osx has an single value array with an array inside
+        cmd_parts = cmd_parts[0]
+        cmd_type = 'subarray'
+
+    cmd_parts.extend(extra_args)
+
+    if cmd_type == 'dict':
+        cmd_parts = [{'task-reference': ' '.join(cmd_parts)}]
+    elif cmd_type == 'unicode':
+        cmd_parts = [' '.join(cmd_parts)]
+    elif cmd_type == 'subarray':
+        cmd_parts = [cmd_parts]
+    return cmd_parts