def post_resource_assign(serv, usr, passw, activity, name): resource = resource_id_from_name(serv, usr, passw, name) if resource: # check if the resource had already been assigned request_data = { 'Field': ['ResourceObjectId'], 'Filter': "ActivityObjectId = '%s' and ResourceObjectId = '%s'" % (str(activity), str(resource)) } resp = m.soap_request(request_data, primaserver, 'ResourceAssignmentService', 'ReadResourceAssignments', primauser, primapasswd) if len(resp) > 0: # already assigned synched = 'already assigned to activity #' + str(activity) shlog.verbose(name + ' ' + synched) else: # actual post request_data = { 'ResourceAssignment': { 'ActivityObjectId': activity, 'ResourceObjectId': resource } } synched = m.soap_request(request_data, serv, 'ResourceAssignmentService', 'CreateResourceAssignments', usr, passw) else: return name + ' not found in resources' return synched
def post_act_complete(server, user, pw, ObjectId, status): # possible status values: "Completed", "In Progress", "Not Started" request_data = {'Activity': {'ObjectId': ObjectId, 'Status': status}} shlog.normal('Making request to change status to ' + status) synched = m.soap_request(request_data, server, 'ActivityService', 'UpdateActivities', user, pw) return synched
def get_primavera_step_count(ActivityId, server, user, passw): request_data = { 'Field': ['ObjectId'], 'Filter': "ActivityObjectId = '%s'" % ActivityId } steps_api = m.soap_request(request_data, server, 'ActivityStepService', 'ReadActivitySteps', user, passw) return len(steps_api)
def get_step_baseline(server, usr, passw, objectid): # request step's baseline id request_data = { 'Field': ['ProjectObjectId'], 'Filter': "ObjectId = '%s'" % str(objectid) } resp = m.soap_request(request_data, server, 'ActivityStepService', 'ReadActivitySteps', usr, passw) return resp[0]['ProjectObjectId']
def post_step_resource_assign(serv, usr, passw, step, name): resource = resource_id_from_name(serv, usr, passw, name) if resource: # check if the resource had already been assigned name = name.replace(',', '') name_first = name.split(' ')[0] name_last = name.split(' ')[-1] request_data = { 'Field': ['Text'], 'Filter': "UDFTypeObjectId = '158' and ForeignObjectId = '%s' and Text like '%%%s%%' and " "Text like '%%%s%%'" % (str(step), str(name_first), str(name_last)) } resp = m.soap_request(request_data, primaserver, 'UDFValueService', 'ReadUDFValues', primauser, primapasswd) if len(resp) > 0: # already assigned synched = 'already assigned to step #' + str(step) shlog.verbose(name + ' ' + synched) else: # actual post try: request_data = { 'Field': ['Name'], 'Filter': "ObjectId = '%s'" % str(resource) } synched = m.soap_request(request_data, serv, 'ResourceService', 'ReadResources', usr, passw) if len(synched) > 0: # if it's not None p6_name = synched[0]['Name'] else: p6_name = None baseline = m.actual_baseline(serv, usr, passw) resp = m.ticket_wipe(primaserver, primauser, primapasswd, step, 158) # just in case shlog.verbose('Posting name ' + p6_name + ' to step #' + str(step)) m.ticket_post(serv, usr, passw, step, baseline, p6_name, 158) except IndexError: return 'IndexError thrown, user not found' else: return name + ' not found in resources' return synched
def post_note(serv, usr, passw, parent, code, note): request_data = { 'ActivityNote': { 'Note': note, 'ActivityObjectId': parent, 'NotebookTopicObjectId': code # 43 and 38 this better never change } } synched = m.soap_request(request_data, serv, 'ActivityNoteService', 'CreateActivityNotes', usr, passw) return synched
def update_step_desc(server, usr, passw, parent, objectid, desc): request_data = { 'ActivityStep': { 'ActivityObjectId': parent, 'ObjectId': objectid, 'Description': desc } } synched = m.soap_request(request_data, server, 'ActivityStepService', 'UpdateActivitySteps', usr, passw) return synched
def user_id_from_name(serv, usr, passw, name): if name: # if it's not None name = name.replace(',', '') name_first = name.split(' ')[0] name_last = name.split(' ')[-1] request_data = { 'Field': ['ObjectId', 'Name'], 'Filter': "PersonalName like '%%%s%%' and PersonalName like '%%%s%%'" % (name_first, name_last) } synched = m.soap_request(request_data, serv, 'UserService', 'ReadUsers', usr, passw) return synched[0]['ObjectId'], synched[0]['Name'] else: return None, None
def resource_id_from_name(serv, usr, passw, name): name = name.replace(',', '') name_first = name.split(' ')[0] name_last = name.split(' ')[-1] request_data = { 'Field': ['ObjectId', 'Id'], 'Filter': "Name like '%%%s%%' and Name like '%%%s%%' and ResourceType = 'Labor' and Id not like 'RS%%'" "" % (name_first, name_last) } if name: # if it's not None synched = m.soap_request(request_data, serv, 'ResourceService', 'ReadResources', usr, passw) try: return synched[0]['ObjectId'] except IndexError: # name not found in resources return None else: return None
def post_color(serv, usr, passw, activity, color, code): # add a checkmark to an activity # colors available: Yellow, Green if color not in ['Yellow', 'Green']: shlog.normal('Color error! ' + str(color) + ' not in list: Yellow, Green') exit(0) request_data = { 'UDFValue': { 'ForeignObjectId': activity, 'ProjectObjectId': m.actual_baseline(serv, usr, passw), 'Indicator': color, 'UDFTypeObjectId': code } } # Import into NCSA JIRA is 153 # Import into LSST JIRA is 148 synched = m.soap_request(request_data, serv, 'UDFValueService', 'CreateUDFValues', usr, passw) shlog.verbose('Server response: ' + str(synched)) return synched
def parent_has_step(server, usr, passw, parent, name): # get step list request_data = { 'Field': ['ObjectId', 'Name'], 'Filter': "ActivityObjectId = '%s'" % parent } shlog_list = '' for field in request_data['Field']: shlog_list += field + ', ' shlog.verbose('Requesting if Activity #' + str(parent) + ' has step ' + name + ', fields: ' + shlog_list[:-2]) steps_api = m.soap_request(request_data, server, 'ActivityStepService', 'ReadActivitySteps', usr, passw) # run CASE INSENSITIVE SPECE-REMOVING check against the results result = None for step in steps_api: confidence = fuzz.WRatio(step['Name'], name) shlog.normal('Comparing:\nJIRA: ' + name + '\nP6: ' + step['Name'] + '\nConfidence: ' + str(confidence)) if confidence >= 94: result = step['ObjectId'] break return result
'ProjectObjectId': m.actual_baseline(primaserver, primauser, primapasswd), # 408 is the one currently active 'ProjectId': 'LSST MREFC', 'WBSObjectId': 4597, 'WBSPath': 'LSST MREFC.MREFC.LSST Construction.Test WBS', # the big dump 'OwnerIDArray': api_owner_obj, 'OwnerNamesArray': api_owner_name } } synched = m.soap_request(request_data, primaserver, 'ActivityService', 'CreateActivities', primauser, primapasswd) created_activity = synched[0] shlog.normal(str(created_activity) + ' ObjectId returned') # post descriptions to the new activity # purpose synched = post_note(primaserver, primauser, primapasswd, created_activity, 38, purpose) # scope synched = post_note(primaserver, primauser, primapasswd, created_activity, 43, scope) # go through all steps and find relevant ones r = 2 while True: step_name = steps_sheet.cell(row=r, column=2).value if step_name == '' or step_name == None or step_name == ' ': break