Skip to content

Instantly share code, notes, and snippets.

@3v1n0
Last active September 6, 2017 06:47
Show Gist options
  • Save 3v1n0/aa6ad749ce29cac15f61 to your computer and use it in GitHub Desktop.
Save 3v1n0/aa6ad749ce29cac15f61 to your computer and use it in GitHub Desktop.
Launchpad Tools
#!/usr/bin/python
import launchpadlib.launchpad
import sys
if len(sys.argv) < 2:
print "You need to pass the bug number to adjust"
sys.exit(1)
lp = launchpadlib.launchpad.Launchpad.login_with(u'rlp', u'production', version='devel')
unity = lp.projects['unity']
bugs = [lp.bugs[int(i)] for i in sys.argv[1:]]
if not len(bugs):
print "Invalid task value"
sys.exit(1)
stable = unity.getMilestone(name='7.2.3')
stable_serie = stable.series_target
for bug in bugs:
upstream_task = None
for r in bug.bug_tasks:
if r.target == unity:
upstream_task = r
break
if not upstream_task:
print "Ipossible to find an upstream task for " + bug.web_link
continue
try:
stable_task = bug.addTask(target=stable_serie)
print "Added new task",stable_task.web_link
stable_task.status = upstream_task.status
stable_task.importance = upstream_task.importance
stable_task.assignee = upstream_task.assignee
stable_task.milestone = stable
stable_task.lp_save()
except Exception as e:
print "Impossible to add new task in " + bug.web_link
#!/usr/bin/python
import sys
import launchpadlib.launchpad
lp = launchpadlib.launchpad.Launchpad.login_with(u'rlp', u'production', version='devel')
unity = lp.projects['unity']
devel = unity.getMilestone(name='7.3.1')
devel_serie = devel.series_target
stable = unity.getMilestone(name='7.2.3')
stable_serie = stable.series_target
bugs = [lp.bugs[int(i)] for i in sys.argv[1:]]
for bug in bugs:
unity_task = None
for t in bug.bug_tasks:
if t.target == unity:
unity_task = t
break
if not unity_task:
print "The bug is not assigned to the project",unity.web_link
continue
unity_bug = unity_task.bug
try:
stable_task = unity_bug.addTask(target=stable_serie)
print "Added new task",stable_task.web_link
stable_task.status = unity_task.status
except Exception as e:
print "Impossible to add new task to " + unity_bug.web_link,
for t in bug.bug_tasks:
if t.target == stable_serie:
stable_task = t
print "Updating it... ",
break
print ""
stable_task.importance = unity_task.importance
stable_task.assignee = unity_task.assignee
stable_task.milestone = stable
stable_task.lp_save()
if unity_task.milestone != devel:
unity_task.milestone = devel
unity_task.lp_save()
#!/usr/bin/python
import os, subprocess, sys
import launchpadlib.launchpad
from lazr.restfulclient.errors import HTTPError
lp = launchpadlib.launchpad.Launchpad.login_with(os.path.basename(sys.argv[0]), u'production', version='devel')
if len(sys.argv) < 2 or not os.path.isfile(sys.argv[1]):
print "Invalid file provided as first parameter"
sys.exit(1)
file_name = sys.argv[1]
try:
file_data = open(file_name, 'rb').read()
except:
print "Impossible to open file %s" % file_name
sys.exit(1)
basename = os.path.basename(file_name)
mime = subprocess.Popen("file -b --mime-type "+file_name, shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
patch = 'diff' in mime or 'patch' in mime
bugs = [lp.bugs[int(i)] for i in sys.argv[2:]]
if not len(bugs):
print "Invalid task values"
sys.exit(1)
print "Bugs found:",len(bugs)
i = 1
for bug in bugs:
print "[%.02f%% %d/%d] Bug %s..." % ((i * 100.0 / len(bugs)), i, len(bugs), bug.web_link),
sys.stdout.flush()
try:
bug.addAttachment(comment=basename, content_type=mime, data=file_data, filename=basename, is_patch=patch):
print "done!"
except:
print "fail!"
i += 1
#!/usr/bin/python
import os, sys
import launchpadlib.launchpad
from lazr.restfulclient.errors import HTTPError
lp = launchpadlib.launchpad.Launchpad.login_with(os.path.basename(sys.argv[0]), u'production', version='devel')
CLEAN_STATES = [ 'Opinion', 'Invalid', 'Won\'t Fix', 'Expired' ]
MOVABLE_STATES = [ 'New', 'Incomplete', 'Confirmed', 'Triaged', 'In Progress' ]
COMPLETED_STATES = [ 'Fix Committed', 'Fix Released' ]
CONVERSION_VALUES = {'Won\'t Fix': 'Invalid', 'Triaged': 'Confirmed'}
ubuntu = lp.distributions['ubuntu']
project_name = sys.argv[1] if len(sys.argv) > 1 else None
status = sys.argv[2] if len(sys.argv) > 2 else None
if not project_name:
print "No project name given..."
sys.exit(1)
is_source = False
if project_name.endswith("_src"):
is_source = True
project_name = project_name.replace("_src", "")
if not status or status not in CLEAN_STATES + MOVABLE_STATES + COMPLETED_STATES:
print "Impossible to mark the bug to status", status
sys.exit(1)
project = lp.projects[project_name] if not is_source else ubuntu.getSourcePackage(name=project_name)
bugs = [lp.bugs[int(i)] for i in sys.argv[3:]]
if not len(bugs):
print "Invalid task values"
sys.exit(1)
print "Bugs found:",len(bugs)
i = 1
for bug in bugs:
print "[%.02f%% %d/%d] Bug %s" % ((i * 100.0 / len(bugs)), i, len(bugs), bug.web_link),
task = None
for t in bug.bug_tasks:
if t.target == project:
task = t
break
if not task:
print "The bug is not assigned to the project",project.web_link
continue
task.status = status
task.lp_save()
print "done!"
i += 1
#!/usr/bin/python
import os, sys
import launchpadlib.launchpad
from lazr.restfulclient.errors import HTTPError
lp = launchpadlib.launchpad.Launchpad.login_with(os.path.basename(sys.argv[0]), u'production', version='devel')
CLEAN_STATES = [ 'Opinion', 'Invalid', 'Won\'t Fix', 'Expired' ]
MOVABLE_STATES = [ 'New', 'Incomplete', 'Confirmed', 'Triaged', 'In Progress' ]
COMPLETED_STATES = [ 'Fix Committed', 'Fix Released' ]
CONVERSION_VALUES = {'Won\'t Fix': 'Invalid', 'Triaged': 'Confirmed'}
ubuntu = lp.distributions['ubuntu']
project_name = sys.argv[1] if len(sys.argv) > 1 else 'unity'
src_project = ubuntu.getSourcePackage(name=project_name)
upstream_project = src_project.upstream_product
upstream_bugs = upstream_project.searchTasks(status=MOVABLE_STATES+COMPLETED_STATES, order_by='-datecreated')
print "Upstream bugs found:",len(upstream_bugs)
i = 1
for task in upstream_bugs:
bug = task.bug
print "[%.02f %d/%d]" % ((i * 100.0 / len(upstream_bugs)), i, len(upstream_bugs)),
try:
found_src = False
for r in task.related_tasks:
if r.target == src_project:
found_src = True
break
if found_src:
print "Bug",bug.web_link,"has already a downstream bug"
i += 1
continue
print "Bug",bug.web_link,"needs to be downstreamed...",
src_task = bug.addTask(target=src_project)
src_task.status = task.status if task.status not in CONVERSION_VALUES.keys() else CONVERSION_VALUES[task.status]
src_task.lp_save()
except HTTPError:
print "ERROR!"
try:
src_task.assignee = task.assignee
src_task.importance = task.importance
src_task.lp_save()
except HTTPError:
print "partially",
print "done!"
i += 1
#!/usr/bin/python
import os, sys
import launchpadlib.launchpad
from lazr.restfulclient.errors import HTTPError
lp = launchpadlib.launchpad.Launchpad.login_with(os.path.basename(sys.argv[0]), u'production', version='devel')
CLEAN_STATES = [ 'Opinion', 'Invalid', 'Won\'t Fix', 'Expired' ]
MOVABLE_STATES = [ 'New', 'Incomplete', 'Confirmed', 'Triaged', 'In Progress' ]
COMPLETED_STATES = [ 'Fix Committed', 'Fix Released' ]
ubuntu = lp.distributions['ubuntu']
project_name = sys.argv[1] if len(sys.argv) > 1 else 'unity'
src_project = ubuntu.getSourcePackage(name=project_name)
upstream_project = src_project.upstream_product
src_bugs = src_project.searchTasks(status=MOVABLE_STATES+COMPLETED_STATES, order_by='-datecreated')
print "Downstream bugs found:",len(src_bugs)
i = 1
for task in src_bugs:
bug = task.bug
print "[%.02f %d/%d]" % ((i * 100.0 / len(src_bugs)), i, len(src_bugs)),
try:
found_upstream = False
for r in task.related_tasks:
if r.target == upstream_project:
found_upstream = True
break
if found_upstream:
print "Bug",bug.web_link,"has already an upstream bug"
i += 1
continue
print "Bug",bug.web_link,"needs to be upstreamed...",
upstream_task = bug.addTask(target=upstream_project)
upstream_task.status = task.status
upstream_task.importance = task.importance
upstream_task.assignee = task.assignee
upstream_task.lp_save()
print "done!"
except HTTPError:
print "ERROR!"
i += 1
#!/usr/bin/python
import launchpadlib.launchpad
MOVABLE_STATES = [ 'New', 'Incomplete', 'Confirmed', 'Triaged', 'In Progress' ]
lp = launchpadlib.launchpad.Launchpad.login_with(u'rlp', u'production', version='devel')
unity = lp.projects['unity']
devel = unity.getMilestone(name='7.3.1')
devel_serie = devel.series_target
stable = unity.getMilestone(name='7.2.3')
stable_serie = stable.series_target
def move_stable_to_devel_adding_stable_task():
global lp, unity, devel, devel_serie, stable, stable_serie
for bug_task in stable.searchTasks(status=MOVABLE_STATES):
bug = bug_task.bug
try:
stable_task = bug.addTask(target=stable_serie)
print "Added new task",stable_task.web_link
stable_task.status = bug_task.status
stable_task.importance = bug_task.importance
stable_task.assignee = bug_task.assignee
stable_task.milestone = stable
stable_task.lp_save()
bug_task.milestone = devel
bug_task.lp_save()
except Exception as e:
print "Impossible to add new task in " + bug.web_link
if bug_task.status in MOVABLE_STATES and bug_task.milestone != devel:
print "Updating task milestone ",bug_task.web_link
bug_task.milestone = devel
bug_task.lp_save()
def move_stable_main_bugs_to_devel():
global lp, unity, devel, devel_serie, stable, stable_serie
for b in stable.searchTasks():
print "Parsing",b.web_link,
if b.target == unity:
if b.milestone == devel:
print "no need to update"
continue
task = b
else:
do_continue = False
for r in b.related_tasks:
if r.target == unity:
if r.milestone == devel:
print "no need to update"
do_continue = True
break
task = r
break
if do_continue:
continue
task.milestone = devel
task.lp_save()
print "updated!"
#!/usr/bin/python
import os, sys
import launchpadlib.launchpad
from lazr.restfulclient.errors import HTTPError
lp = launchpadlib.launchpad.Launchpad.login_with(os.path.basename(sys.argv[0]), u'production', version='devel')
CLEAN_STATES = [ 'Opinion', 'Invalid', 'Won\'t Fix', 'Expired' ]
MOVABLE_STATES = [ 'New', 'Incomplete', 'Confirmed', 'Triaged', 'In Progress' ]
COMPLETED_STATES = [ 'Fix Committed', 'Fix Released' ]
CONVERSION_VALUES = {'Won\'t Fix': 'Invalid', 'Triaged': 'Confirmed'}
ubuntu = lp.distributions['ubuntu']
# project_name = sys.argv[1] if len(sys.argv) > 1 else 'unity'
project_name = 'unity'
src_project = ubuntu.getSourcePackage(name=project_name)
upstream_project = src_project.upstream_product
bugs = [lp.bugs[int(i)] for i in sys.argv[1:]]
if not len(bugs):
print "NO bugs added, looking for invalid ones..."
states = MOVABLE_STATES + COMPLETED_STATES
src_bugs = src_project.searchTasks(status=states, order_by='-datecreated')
print "Found source bugs ",len(src_bugs)
src_ids = [task.self_link.split('/')[-1] for task in src_bugs]
upstream_bugs = upstream_project.searchTasks(status=states, order_by='-datecreated')
print "Found upstream bugs ",len(upstream_bugs)
upstream_ids = [task.self_link.split('/')[-1] for task in upstream_bugs]
unique = set()
for id in set(src_ids + upstream_ids):
if id in src_ids and id not in upstream_ids:
unique.add(id)
elif id in upstream_ids and id not in src_ids:
unique.add(id)
bugs = [lp.bugs[id] for id in unique]
if not len(bugs):
print "Invalid task values"
sys.exit(1)
print "Bugs found:",len(bugs)
i = 1
for bug in bugs:
print "[%.02f%% %d/%d] Bug %s" % ((i * 100.0 / len(bugs)), i, len(bugs), bug.web_link),
try:
main_task = None
upstream_task = None
src_task = None
for r in bug.bug_tasks:
if r.target == upstream_project:
upstream_task = r
main_task = upstream_task
break
for r in bug.bug_tasks:
if r.target == src_project:
src_task = r
if not main_task:
main_task = src_task
break
if not main_task:
i += 1
print "No main task found"
continue
except HTTPError:
print "ERROR!"
if src_task != main_task:
try:
if not src_task:
print "needs to be downstreamed...",
src_task = bug.addTask(target=src_project)
if src_task.status != 'Expired':
new_status = main_task.status if main_task.status not in CONVERSION_VALUES.keys() else CONVERSION_VALUES[main_task.status]
src_task.status = new_status
src_task.lp_save()
except HTTPError:
print "ERROR!"
i += 1
continue
try:
src_task.assignee = main_task.assignee
src_task.importance = main_task.importance
src_task.lp_save()
except HTTPError:
print "partially",
if upstream_task != main_task:
try:
if not upstream_task:
print "needs to be upstreamed...",
upstream_task = bug.addTask(target=upstream_project)
if upstream_task.status != 'Expired':
upstream_task.status = main_task.status
upstream_task.importance = main_task.importance
upstream_task.assignee = main_task.assignee
upstream_task.lp_save()
except Exception:
print "ERROR!"
i += 1
continue
print "done!"
i += 1
#!/usr/bin/python
import os, sys
import launchpadlib.launchpad
lp = launchpadlib.launchpad.Launchpad.login_with(os.path.basename(sys.argv[0]), u'production', version='devel')
CLEAN_STATES = [ 'Opinion', 'Invalid', 'Won\'t Fix', 'Expired' ]
MOVABLE_STATES = [ 'New', 'Incomplete', 'Confirmed', 'Triaged', 'In Progress' ]
COMPLETED_STATES = [ 'Fix Committed', 'Fix Released' ]
CONVERSION_VALUES = {'Won\'t Fix': 'Invalid', 'Triaged': 'Confirmed'}
ubuntu = lp.distributions['ubuntu']
project_name = sys.argv[1] if len(sys.argv) > 1 else 'unity'
src_project = ubuntu.getSourcePackage(name=project_name)
upstream_project = src_project.upstream_product
src_bugs = src_project.searchTasks(status='New', order_by='-datecreated')
print "Downstream bugs found:",len(src_bugs)
i = 1
for task in src_bugs:
bug = task.bug
print "[%.02f %d/%d]" % ((i * 100.0 / len(src_bugs)), i, len(src_bugs)),
try:
upstream_task = None
for r in task.related_tasks:
if r.target == upstream_project:
upstream_task = r
break
if not upstream_task:
print "Bug",bug.web_link,"has NOT an upstream task!!!!"
i += 1
continue
required_status = upstream_task.status if upstream_task.status not in CONVERSION_VALUES.keys() else CONVERSION_VALUES[upstream_task.status]
if required_status == task.status:
print "Bug",bug.web_link,"is fine"
i += 1
continue
print "Bug",bug.web_link,"needs to be updated...",
task.status = required_status
task.lp_save();
except:
print "ERROR!"
print "done!"
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment