from __future__ import print_function import P4 import shlex import traceback p4 = P4.P4() p4.port = 'workshop.perforce.com:1666' p4.connect() print('connected.') jobs = [] job_mapping = {} for job in p4.run_jobs(shlex.split('-e "status=* ^job=job*"')): jobs.append(job) newjob = p4.fetch_job() for key in job: newjob[key] = job[key] newjob['Job'] = 'new' newtype = newjob.get('Type') if newtype not in ('Feature', 'Bug'): newjob['Type'] = 'Feature' p4.input = newjob # print(newjob) try: rv = p4.run_job('-i') except Exception as e: print(traceback.format_exc()) continue if not rv: # shouldn't happen continue newjobname = rv[0].split()[1] fixes = p4.run_fixes(['-j', job.get('Job')]) for fix in fixes: print(fix) p4.run_fix(['-s', fix.get('Status'), '-c', fix.get('Change'), newjobname]) p4.run_fix(['-d', '-c', fix.get('Change'), job.get('Job')]) p4.run_job(['-d', job.get('Job')]) job_mapping[job.get('Job')] = newjobname for job in job_mapping: print('{} -> {}'.format(job, job_mapping[job]))