-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDumpCurrentValues.py
46 lines (32 loc) · 1.59 KB
/
DumpCurrentValues.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
import json
from pyral import Rally, rallyWorkset
class DumpCurrentValues:
def __init__(self, rally):
self.rally = rally
return
def run(self, element_name, attribute_name):
response = self.rally.get('TypeDefinition', fetch=True, query='ElementName = "{0}"'.format(element_name))
if response.errors:
print(response.errors)
element_typedef = response.next()
attributes = element_typedef.Attributes
attribute = [attribute for attribute in attributes if attribute.Name == attribute_name][0]
attribute_definition_objectid = attribute.ObjectID # Post this to /create to add a value
# Get the AllowedValue objects
allowed_values = attribute.AllowedValues
for value in allowed_values:
print(value.StringValue)
if __name__ == "__main__":
if ( len(sys.argv) != 2 ):
print("ERROR: Command requires one (and only one) argument.")
print("USAGE: python DumpCurrentValues.py config/config.json")
sys.exit(-1)
config_filename = sys.argv[1]
with open(config_filename, "r") as config_file:
config = json.load(config_file)
options = [opt for opt in sys.argv[1:] if opt.startswith('--')]
server, user, password, apikey, workspace, project = rallyWorkset(options)
rally = Rally(config['server'], user, password, apikey=apikey, workspace=config['workspace'], project=config['project'])
manager = DumpCurrentValues(rally)
manager.run(config['element_name'], config['attribute_name'])