Skip to content

Instantly share code, notes, and snippets.

@freyes
Created September 5, 2017 01:39
Show Gist options
  • Select an option

  • Save freyes/879977febc5c3b3558802b4d25b47614 to your computer and use it in GitHub Desktop.

Select an option

Save freyes/879977febc5c3b3558802b4d25b47614 to your computer and use it in GitHub Desktop.
attach files to a launchpad bug from the command line
#!/usr/bin/python
#
# Usage:
# $ lp-attach 1234 foo.debdiff bar.debdiff
#
import os
import sys
from launchpadlib.launchpad import Launchpad
def usage():
print('Usage:\n\tlp-attach <bug_number> <file> [<file> <file> ...]')
if len(sys.argv) <= 2:
usage()
sys.exit(1)
def no_credential():
print("Can't proceed without Launchpad credential.")
sys.exit()
launchpad = Launchpad.login_with('lp-attach', 'production', credential_save_failed=no_credential)
try:
bug = launchpad.bugs[int(sys.argv[1])]
except ValueError:
print("ERROR: '%s' not a bug number" % sys.argv[1])
usage()
sys.exit(1)
for fname in sys.argv[2:]:
if not os.path.isfile(fname):
continue
if os.path.splitext(fname)[1] in ['.debdiff', '.patch']:
is_patch = True
else:
is_patch = False
with open(fname, 'rb') as f:
bug.addAttachment(comment="",
data=f.read(),
description="",
is_patch=is_patch,
filename=os.path.basename(fname))
res = bug.lp_save()
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment