[packagedb-cli] Revise the orphan --all procedure to reduce the number of call to pkgdb.
by Pierre-YvesChibon
commit 25a34ed0119b3604f50af89b383b12af69a92a4f
Author: Pierre-Yves Chibon py(a)chibon.fr <pingou(a)pingoured.fr>
Date: Tue Jun 7 15:25:01 2011 +0200
Revise the orphan --all procedure to reduce the number of call to pkgdb.
We are now using the PackageDB client from python-fedora to do mass orphan of all the packages for a given user.
pkgdb.py | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index cf107c4..51d7e6e 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -642,11 +642,12 @@ def orphan_package(packagename, branch='devel', allpkgs=False,
log.debug("Orphan all packages")
if branch == "all":
log.debug("Orphan in all branches")
- branches = _get_active_branches()
- for branch in branches:
- _orphan_one_package(pkg, branch, username, password)
+ pkgdbclient.change_owner(pkgdbclient.username, 'orphan',
+ "*")
else:
- _orphan_one_package(pkg, branch, username, password)
+ log.debug("Orphan branch {0}".format(branch))
+ pkgdbclient.change_owner(pkgdbclient.username, 'orphan',
+ "*", branch)
elif re.match(packagename, pkg):
log.debug("motif : {0}".format(motif))
log.debug("package : {0}".format(pkg))
12 years, 11 months
[packagedb-cli] Fix the pkgdb orphan --all usecase and make the output from get_packager_info optionnal.
by Pierre-YvesChibon
commit eadac5475c9866513b301530b30dba174ca357dc
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Jun 6 23:11:20 2011 +0200
Fix the pkgdb orphan --all usecase and make the output from get_packager_info optionnal.
At the moment we run one query per packages, we should be able to improve this in the future.
get_packager_info now has an extra parameter to hide its output where needed (cleanest way?).
pkgdb.py | 43 +++++++++++++++++++++++++++++--------------
1 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index 659849b..cf107c4 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -40,6 +40,7 @@ logging.basicConfig()
log = logging.getLogger("pkgdb")
if '--debug' in sys.argv:
log.setLevel(logging.DEBUG)
+ #pkgdbclient.debug = True
elif '--verbose' in sys.argv:
log.setLevel(logging.INFO)
@@ -355,7 +356,7 @@ def get_orphaned_packages(motif=None, eol=False):
log.info(pkgdbinfo.keys())
-def get_packager_info(packager):
+def get_packager_info(packager, output=True):
"""
Retrieve the list of all the package for which the given packager
has
@@ -375,15 +376,18 @@ def get_packager_info(packager):
pkgs = []
if pkgdbinfo['eol']:
- print "User EOL'd"
+ if output:
+ print "User EOL'd"
if 'pkgs' in pkgdbinfo:
for pkg in pkgdbinfo['pkgs']:
log.info(pkg.keys())
pkgs.append(pkg['name'])
- print " ", pkg['name'], " " * (30 - len(pkg['name'])), \
- pkg['summary']
+ if output:
+ print " ", pkg['name'], " " * (30 - len(pkg['name'])), \
+ pkg['summary']
#pkgdbinfo['statusMap'][pkg['statuscode']]
- print "Total: {0} packages".format(len(pkgdbinfo['pkgs']))
+ if output:
+ print "Total: {0} packages".format(len(pkgdbinfo['pkgs']))
return pkgs
@@ -627,10 +631,13 @@ def orphan_package(packagename, branch='devel', allpkgs=False,
branch = 'devel'
_get_client_authentified(username=username, password=password)
- pkgs = get_packager_info(pkgdbclient.username)
- # transform the packagename to make it a regex
- motif = "^" + packagename.replace("*", ".*") + "$"
+ pkgs = get_packager_info(pkgdbclient.username, output=False)
+ log.debug("Packages: {0}".format(pkgs))
+ if packagename is not None:
+ # transform the packagename to make it a regex
+ motif = "^" + packagename.replace("*", ".*") + "$"
for pkg in pkgs:
+ log.info("Package: {0}".format(pkg))
if allpkgs is True:
log.debug("Orphan all packages")
if branch == "all":
@@ -696,7 +703,7 @@ def retire_package(packagename, branch='devel', allpkgs=False,
_retire_one_package(packagename, branch, username, password)
-def setup_action_parser(action):
+def setup_action_parser(action, last_args=None):
"""
Parse the remaining argument for action specific arguments.
@@ -733,15 +740,23 @@ def setup_action_parser(action):
help="Pattern to query")
elif action == 'orphan':
- parser.add_argument('package',
+ if "--all" in last_args:
+ parser.add_argument('--package')
+ parser.add_argument('--branch')
+ parser.add_argument('--retire', action="store_true", default=False,
+ help="Retire the given package")
+ parser.add_argument('--all', action="store_true", default=False,
+ help="Orphan all your packages")
+ else:
+ parser.add_argument('package',
help="Name of the package to orphan or " \
"simple pattern")
- parser.add_argument('branch', default='devel', nargs="?",
+ parser.add_argument('branch', default='devel', nargs="?",
help="Branch of the package to orphan " \
"(default: devel, can be: all)")
- parser.add_argument('--retire', action="store_true", default=False,
+ parser.add_argument('--retire', action="store_true", default=False,
help="Retire the given package")
- parser.add_argument('--all', action="store_true", default=False,
+ parser.add_argument('--all', action="store_true", default=False,
help="Orphan all your packages")
elif action == "request":
@@ -808,7 +823,7 @@ def main():
raise argparse.ArgumentTypeError(
"command must be one of: {0}".format(','.join(cmdlist)))
# Parse action-specific args
- action_parser = setup_action_parser(action)
+ action_parser = setup_action_parser(action, arg.argument)
log.info("*** {0}".format(", ".join(arg.argument)))
args = action_parser.parse_args(arg.argument)
if action == "acl":
12 years, 11 months
[packagedb-cli] Fix methods to approve/deny ACL and raise error when the package ID cannot be found
by Pierre-YvesChibon
commit 23c4af1214d72c50135ef00f6ed136518519b24a
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Jun 6 22:28:50 2011 +0200
Fix methods to approve/deny ACL and raise error when the package ID cannot be found
One can now approve or deny ACL for package he owns and for which package_id can be retrieved.
When the package_id cannot be retrieved, we generate an error.
pkgdb.py | 114 +++++++++++++++++++++++++++++++------------------------------
1 files changed, 58 insertions(+), 56 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index 94c7813..659849b 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -53,6 +53,13 @@ class ActionError(Exception):
pass
+class PackageIDError(Exception):
+ """ This class is raised when a package_id could not be found for a
+ specific package name or combination of package name and branch.
+ """
+ pass
+
+
def _get_client_authentified(username=None, password=None):
""" Returned a BaseClient with authentification
@@ -128,7 +135,8 @@ def _get_package_id(packagename, branch):
can be "devel", "f-14"...
:return package_id a string of the package_id in the packageListings
"""
- log.debug("Retrieve package_id from pkgdb for {0}".format(packagename))
+ log.debug("Retrieve package_id from pkgdb for {0} branch {1}".format(
+ packagename, branch))
pkgdbinfo = pkgdbclient.send_request('/acls/name/{0}'.format(
packagename, auth=False))
if 'packageListings' in pkgdbinfo.keys():
@@ -138,7 +146,12 @@ def _get_package_id(packagename, branch):
packagename, pkgdbinfo['packageListings'][0]['id']))
return branches['id']
else:
- return None
+ # line splitted for now, when translation will come in line
+ # the splitted string should be put back together.
+ raise PackageIDError(
+ "The package_id for package '{0}' in branch '{1}' could not be" \
+ " found".format(
+ packagename, branch))
def _get_active_branches():
@@ -223,12 +236,6 @@ def _retire_one_package(packagename, branch='devel', username=None,
_get_client_authentified(username=username, password=password)
packageid = _get_package_id(packagename, branch)
- if packageid is None:
- print "Cannot retire package {0} on branch {1}, "\
- "package ID could not be found".format(packagename,
- branch)
- return
-
pkgdbinfo = pkgdbclient.send_request(
'/acls/dispatcher/toggle_retirement',
auth=True, req_params={'pkg_listing_id': packageid})
@@ -240,6 +247,41 @@ def _retire_one_package(packagename, branch='devel', username=None,
pkgdbinfo["retirement"], reset)
+def _answer_acl(action, user, packagename, answer, branch):
+ """
+ Answer a requested ACL.
+ This method allows you to approve or deny a single acl.
+
+ :arg action is the name of the ACL
+ :arg user is the FAS name of the user who requested the ACL
+ :arg packagename is the name of the package
+ :arg answer your answer to the request (approve/deny)
+ :karg branch is the name of the branch for which you reply
+ """
+ packageid = _get_package_id(packagename, branch)
+ log.debug(
+ "Answer acl {0} for user {1} and package {2} ({3}) on branch {4}".format(
+ action, user, packagename, packageid, branch))
+ params = {"pkgid": packageid, "person_name": user,
+ "new_acl": action, "statusname": answer}
+ pkgdbinfo = pkgdbclient.send_request(
+ '/acls/dispatcher/set_acl_status',
+ auth=True, req_params=params)
+ log.debug(pkgdbinfo)
+ if pkgdbinfo['status'] is True:
+ print "{0}{1} {2}{3} for {4} on package {5} branch {6}".format(
+ bold,
+ action,
+ answer,
+ reset,
+ pkgdbclient.username,
+ packagename,
+ branch)
+ else:
+ print "ACL request could not be {0}, do you have the rights to" \
+ " so?".format(answer)
+
+
def get_packages(motif=None):
"""
Retrieve the list of all packages in packagedb.
@@ -536,7 +578,8 @@ def answer_acl_request(packagename, action, user, answer, branch=None,
username=None, password=None):
"""
Answer a requested ACL.
- This method allows you to approve or deny a requested acl.
+ This method allows you to approve or deny a specific requested acl
+ or all acl requested by the user.
:arg packagename is the name of the package
:arg action is the name of the ACL
@@ -554,57 +597,16 @@ def answer_acl_request(packagename, action, user, answer, branch=None,
raise ActionError("Action '{0}' is not in the list: {1},all".format(
action, ",".join(actionlist)))
_get_client_authentified(username=username, password=password)
- packageid = _get_package_id(packagename, branch)
- # Answer all branches
+ # Answer all actions requested
if action == 'all':
log.debug("Answer all acl for user: {0}".format(
pkgdbclient.username))
for action in actionlist:
- log.debug(
- "Answer acl {0} for user {1} and package {2} on branch {3}".format(
- action, user, packagename, branch))
- params = {"pkgid": packageid, "person_name": user,
- "new_acl": action, "statusname": answer}
- pkgdbinfo = pkgdbclient.send_request(
- '/acls/dispatcher/set_acl_status',
- auth=True, req_params=params)
- log.debug(pkgdbinfo)
- if 'aclStatus' in pkgdbinfo.keys():
- msg = pkgdbinfo['aclStatus']
- else:
- msg = pkgdbinfo['message']
- log.info(
- "{0}{1}{3} for {4} on package {5} branch {6}".format(
- bold,
- msg,
- reset,
- pkgdbclient.username,
- packagename,
- branch))
- # else we anser only the given one
+ _answer_acl(action, user, packagename, answer, branch)
+ # else we answer only the given one
else:
- log.debug(
- "Answer acl {0} for user {1} and package {2} on branch {3}".format(
- action, user, packagename, branch))
- params = {"pkgid": packageid, "person_name": user,
- "new_acl": action, "statusname": answer}
- pkgdbinfo = pkgdbclient.send_request(
- '/acls/dispatcher/set_acl_status',
- auth=True, req_params=params)
- log.debug(pkgdbinfo)
- if 'aclStatus' in pkgdbinfo.keys():
- msg = pkgdbinfo['aclStatus']
- else:
- msg = pkgdbinfo['message']
- log.info(
- "{0}{1}{2}{3} for {4} on package {5} branch {6}".format(
- bold,
- msg,
- reset,
- pkgdbclient.username,
- packagename,
- branch))
+ _answer_acl(action, user, packagename, answer, branch)
def orphan_package(packagename, branch='devel', allpkgs=False,
@@ -862,9 +864,9 @@ def main():
log.info("branch : {0}".format(args.branch))
log.info("approve : {0}".format(args.approve))
log.info("deny : {0}".format(args.deny))
- answer = args.deny
+ answer = "Denied"
if args.approve:
- answer = args.approve
+ answer = "Approved"
answer_acl_request(args.package, args.action, args.user,
answer, args.branch, arg.username, arg.password)
12 years, 11 months
[packagedb-cli] Start implementing methods to approve or deny requested ACL
by Pierre-YvesChibon
commit ef670b2a109cc95747364d4b65555ceecba73901
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Thu Jun 2 12:37:32 2011 +0200
Start implementing methods to approve or deny requested ACL
pkgdb.py | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 110 insertions(+), 4 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index d53ac8b..94c7813 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -43,7 +43,7 @@ if '--debug' in sys.argv:
elif '--verbose' in sys.argv:
log.setLevel(logging.INFO)
-cmdlist = ['acl', 'list', 'orphan', 'request']
+cmdlist = ['acl', 'list', 'request', 'update', 'orphan']
actionlist = ['watchbugzilla', 'watchcommits', 'commit', 'approveacls']
@@ -532,6 +532,81 @@ def toggle_acl(packagename, action, branch='devel', username=None,
branch))
+def answer_acl_request(packagename, action, user, answer, branch=None,
+ username=None, password=None):
+ """
+ Answer a requested ACL.
+ This method allows you to approve or deny a requested acl.
+
+ :arg packagename is the name of the package
+ :arg action is the name of the ACL
+ :arg user is the FAS name of the user who requested the ACL
+ :arg answer your answer to the request (approve/deny)
+ :karg branch is the name of the branch for which you reply
+ (default = devel)
+ :karg username your FAS username
+ :karg password your FAS password
+ """
+ if branch is None:
+ branch = 'devel'
+
+ if action not in actionlist and action != 'all':
+ raise ActionError("Action '{0}' is not in the list: {1},all".format(
+ action, ",".join(actionlist)))
+ _get_client_authentified(username=username, password=password)
+ packageid = _get_package_id(packagename, branch)
+
+ # Answer all branches
+ if action == 'all':
+ log.debug("Answer all acl for user: {0}".format(
+ pkgdbclient.username))
+ for action in actionlist:
+ log.debug(
+ "Answer acl {0} for user {1} and package {2} on branch {3}".format(
+ action, user, packagename, branch))
+ params = {"pkgid": packageid, "person_name": user,
+ "new_acl": action, "statusname": answer}
+ pkgdbinfo = pkgdbclient.send_request(
+ '/acls/dispatcher/set_acl_status',
+ auth=True, req_params=params)
+ log.debug(pkgdbinfo)
+ if 'aclStatus' in pkgdbinfo.keys():
+ msg = pkgdbinfo['aclStatus']
+ else:
+ msg = pkgdbinfo['message']
+ log.info(
+ "{0}{1}{3} for {4} on package {5} branch {6}".format(
+ bold,
+ msg,
+ reset,
+ pkgdbclient.username,
+ packagename,
+ branch))
+ # else we anser only the given one
+ else:
+ log.debug(
+ "Answer acl {0} for user {1} and package {2} on branch {3}".format(
+ action, user, packagename, branch))
+ params = {"pkgid": packageid, "person_name": user,
+ "new_acl": action, "statusname": answer}
+ pkgdbinfo = pkgdbclient.send_request(
+ '/acls/dispatcher/set_acl_status',
+ auth=True, req_params=params)
+ log.debug(pkgdbinfo)
+ if 'aclStatus' in pkgdbinfo.keys():
+ msg = pkgdbinfo['aclStatus']
+ else:
+ msg = pkgdbinfo['message']
+ log.info(
+ "{0}{1}{2}{3} for {4} on package {5} branch {6}".format(
+ bold,
+ msg,
+ reset,
+ pkgdbclient.username,
+ packagename,
+ branch))
+
+
def orphan_package(packagename, branch='devel', allpkgs=False,
username=None, password=None):
"""
@@ -648,7 +723,7 @@ def setup_action_parser(action):
parser.add_argument('--orphaned', action="store_true", default=False,
dest='orphaned', help="List all orphaned packages")
parser.add_argument('--eol', action="store_true", default=False,
- dest='eol',
+ dest='eol',
help="List all orphaned and eol'd packages")
parser.add_argument('--user', dest='username', default=False,
help="List all the packages of the user <user>")
@@ -671,10 +746,27 @@ def setup_action_parser(action):
parser.add_argument('package', help="Name of the package")
parser.add_argument("action",
help="Request a specific ACL for this package " \
- "(actions are {0})".format(", ".join(actionlist)))
+ "(actions are {0},all)".format(", ".join(actionlist)))
+ parser.add_argument('branch', default='devel', nargs="?",
+ help="Branch of the package for which the ACL is " \
+ "requested (default: devel, can be: all)")
+
+ elif action == "update":
+ parser.add_argument('package', help="Name of the package")
+ parser.add_argument("action",
+ help="Request a specific ACL for this package " \
+ "(actions are {0},all)".format(", ".join(actionlist)))
+ parser.add_argument('user',
+ help="FAS username of the person who requested ACL " \
+ "on this package")
parser.add_argument('branch', default='devel', nargs="?",
help="Branch of the package for which the ACL is " \
- "requested (default: devel)")
+ "requested (default: devel, can be: all)")
+ parser.add_argument('--approve', action="store_true", default=False,
+ help="Approve the requested ACL")
+ parser.add_argument('--deny', action="store_true", default=False,
+ help="Deny the requested ACL")
+
return parser
@@ -762,6 +854,20 @@ def main():
toggle_acl(args.package, args.action, args.branch,
arg.username, arg.password)
+ elif action == "update":
+ log.info("user : {0}".format(arg.username))
+ log.info("package : {0}".format(args.package))
+ log.info("acl : {0}".format(args.action))
+ log.info("requester : {0}".format(args.user))
+ log.info("branch : {0}".format(args.branch))
+ log.info("approve : {0}".format(args.approve))
+ log.info("deny : {0}".format(args.deny))
+ answer = args.deny
+ if args.approve:
+ answer = args.approve
+ answer_acl_request(args.package, args.action, args.user,
+ answer, args.branch, arg.username, arg.password)
+
if __name__ == '__main__':
try:
12 years, 11 months
[packagedb-cli] Rename the parser variable and layout the code
by Pierre-YvesChibon
commit 83697f1a77d2cafa258cc531d4b368675f129312
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Thu Jun 2 12:12:37 2011 +0200
Rename the parser variable and layout the code
pkgdb.py | 84 ++++++++++++++++++++++++++++++++-----------------------------
1 files changed, 44 insertions(+), 40 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index 10e7614..d53ac8b 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -627,51 +627,55 @@ def setup_action_parser(action):
parsed. Actions can be "acl" or "list".
"""
log.info('Action called: {0}'.format(action))
- p = argparse.ArgumentParser(usage="%(prog)s {0} [options]".format(action))
+ parser = argparse.ArgumentParser(
+ usage="%(prog)s {0} [options]".format(action))
if action == 'acl':
- p.add_argument('package', help="Name of the package to query")
- p.add_argument('branch', default='devel', nargs="?",
+ parser.add_argument('package', help="Name of the package to query")
+ parser.add_argument('branch', default='devel', nargs="?",
help="Branch of the package to query")
- p.add_argument('--pending', action="store_true", default=False,
- help="Display only ACL awaiting review")
- p.add_argument('--noextra', action="store_false", default=True,
- help="Do not display extra information (number of bugs"\
- " opened and last build)")
+ parser.add_argument('--pending', action="store_true", default=False,
+ help="Display only ACL awaiting review")
+ parser.add_argument('--noextra', action="store_false", default=True,
+ help="Do not display extra information (number of " \
+ "bugs opened and last build)")
elif action == 'list':
- p.add_argument('--all', action="store_true", default=False,
- dest='all', help="List all packages starting with the" \
- " given pattern (without pattern this may take a while)"
- )
- p.add_argument('--orphaned', action="store_true", default=False,
- dest='orphaned', help="List all orphaned packages")
- p.add_argument('--eol', action="store_true", default=False,
- dest='eol', help="List all orphaned and eol'd packages")
- p.add_argument('--user', dest='username', default=False,
- help="List all the packages of the user <user>")
- p.add_argument('pattern', default=None, nargs="?",
- help="Pattern to query")
+ parser.add_argument('--all', action="store_true", default=False,
+ dest='all', help="List all packages starting " \
+ "with the given pattern (without pattern this may " \
+ "take a while)")
+ parser.add_argument('--orphaned', action="store_true", default=False,
+ dest='orphaned', help="List all orphaned packages")
+ parser.add_argument('--eol', action="store_true", default=False,
+ dest='eol',
+ help="List all orphaned and eol'd packages")
+ parser.add_argument('--user', dest='username', default=False,
+ help="List all the packages of the user <user>")
+ parser.add_argument('pattern', default=None, nargs="?",
+ help="Pattern to query")
elif action == 'orphan':
- p.add_argument('package', help="Name of the package to orphan")
- p.add_argument('branch', default='devel', nargs="?",
+ parser.add_argument('package',
+ help="Name of the package to orphan or " \
+ "simple pattern")
+ parser.add_argument('branch', default='devel', nargs="?",
help="Branch of the package to orphan " \
"(default: devel, can be: all)")
- p.add_argument('--retire', action="store_true", default=False,
- help="Retire the given package")
- p.add_argument('--all', action="store_true", default=False,
- help="Orphan all your packages")
+ parser.add_argument('--retire', action="store_true", default=False,
+ help="Retire the given package")
+ parser.add_argument('--all', action="store_true", default=False,
+ help="Orphan all your packages")
elif action == "request":
- p.add_argument('package', help="Name of the package")
- p.add_argument("action",
- help="Request a specific ACL for this package (actions"\
- " are {0})".format(", ".join(actionlist)))
- p.add_argument('branch', default='devel', nargs="?",
+ parser.add_argument('package', help="Name of the package")
+ parser.add_argument("action",
+ help="Request a specific ACL for this package " \
+ "(actions are {0})".format(", ".join(actionlist)))
+ parser.add_argument('branch', default='devel', nargs="?",
help="Branch of the package for which the ACL is " \
"requested (default: devel)")
- return p
+ return parser
def setup_parser():
@@ -679,22 +683,22 @@ def setup_parser():
Set the main arguments.
"""
usage = "\nCommands: {0}".format(', '.join(cmdlist))
- p = argparse.ArgumentParser(
+ parser = argparse.ArgumentParser(
usage="%(prog)s [global options] COMMAND [options]" + usage,
prog="pkgdb")
# General connection options
- p.add_argument('command')
- p.add_argument('argument', nargs=argparse.REMAINDER)
- p.add_argument('--user', dest="username",
+ parser.add_argument('command')
+ parser.add_argument('argument', nargs=argparse.REMAINDER)
+ parser.add_argument('--user', dest="username",
help="FAS username")
- p.add_argument('--password', dest="password",
+ parser.add_argument('--password', dest="password",
help="FAS password (if not provided, will be asked " \
"later)")
- p.add_argument('--verbose', action='store_true',
+ parser.add_argument('--verbose', action='store_true',
help="give more info about what's going on")
- p.add_argument('--debug', action='store_true',
+ parser.add_argument('--debug', action='store_true',
help="output bunches of debugging info")
- return p
+ return parser
def main():
12 years, 11 months
[packagedb-cli] Reduce code redundancy by creating the _get_last_build function
by Pierre-YvesChibon
commit d9bfc2151d896bc31be32e286d318028027905d9
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Thu Jun 2 12:06:50 2011 +0200
Reduce code redundancy by creating the _get_last_build function
This function is used to query the last build information for a given package and a given tag. The function "get_last_build" makes use of it to query updates and updates-testing for tag containing "f" (as opposed to rawhide which has no updates nor updates-testing).
pkgdb.py | 71 ++++++++++++++++++++++++++++++++-----------------------------
1 files changed, 37 insertions(+), 34 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index 191833c..10e7614 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -154,6 +154,35 @@ def _get_active_branches():
return branches.keys()
+def _get_last_build(packagename, tag):
+ """
+ Print information about the last build of a package for a given koji
+ tag.
+
+ :arg packagename the name of the package for which we are looking for
+ the last build.
+ :arg tag the tag used in koji. See `koji list-tags` for the complete
+ list of available tag.
+ """
+ log.debug("Search last build for {0} in {1}".format(packagename, tag))
+ data = kojiclient.getLatestBuilds(tag,
+ package=packagename)
+ versions = []
+ for build in data:
+ nvr = "{0}-{1}-{2}".format(
+ build['package_name'],
+ build['version'],
+ build['release'])
+ versions.append(nvr)
+ print "{0}Last build:{1}{2} by {3} for {4} in {5}".rstrip().format(
+ " " * 8,
+ " " * 5,
+ build['completion_time'].split(" ")[0],
+ build['owner_name'],
+ version,
+ tag)
+
+
def _orphan_one_package(packagename, branch='devel', username=None,
password=None):
"""
@@ -349,6 +378,7 @@ def get_package_info(packagename, branch=None, pending=False,
if 'packageListings' in pkgdbinfo:
print pkgdbinfo['packageListings'][0]['package']['summary']
if extra:
+ # print the number of opened bugs
log.debug("Query bugzilla")
bugbz = bzclient.query(
{'bug_status': ['NEW', 'ASSIGNED', 'NEEDINFO'],
@@ -399,6 +429,7 @@ def get_package_info(packagename, branch=None, pending=False,
print info
if extra:
+ # print the last build
tag = collection['collection']['koji_name']
get_last_build(packagename, tag)
@@ -423,40 +454,11 @@ def get_last_build(packagename, tag):
# for updates and updates-testing
if "f" in tag:
tag = tag + "-updates"
- log.debug("Search last build for {0} in {1}".format(packagename, tag))
- data = kojiclient.getLatestBuilds(tag,
- package=packagename)
- versions = []
- for build in data:
- nvr = "{0}-{1}-{2}".format(
- build['package_name'],
- build['version'],
- build['release'])
- versions.append(nvr)
- print "{0}Last build:{1}{2} by {3} for {4} in Updates".rstrip().format(
- " " * 8,
- " " * 5,
- build['completion_time'].split(" ")[0],
- build['owner_name'],
- version)
- if "f" in tag:
+ _get_last_build(packagename, tag)
tag = tag + "-testing"
- log.debug("Search last build for {0} in {1}".format(packagename, tag))
- data = kojiclient.getLatestBuilds(tag,
- package=packagename)
- for build in data:
- nvr = "{0}-{1}-{2}".format(
- build['package_name'], build['version'],
- build['release'])
- if nvr not in versions:
- versions.append(nvr)
- print \
- "{0}Last build:{1}{2} by {3} for {4} in Updates-testing".format(
- " " * 6,
- " " * 5,
- build['completion_time'].split(" ")[0],
- build['owner_name'],
- nvr)
+ _get_last_build(packagename, tag)
+ else:
+ _get_last_build(packagename, tag)
def toggle_acl(packagename, action, branch='devel', username=None,
@@ -550,7 +552,7 @@ def orphan_package(packagename, branch='devel', allpkgs=False,
pkgs = get_packager_info(pkgdbclient.username)
# transform the packagename to make it a regex
- motif = "^" + packagename.replace("*",".*") + "$"
+ motif = "^" + packagename.replace("*", ".*") + "$"
for pkg in pkgs:
if allpkgs is True:
log.debug("Orphan all packages")
@@ -575,6 +577,7 @@ def orphan_package(packagename, branch='devel', allpkgs=False,
print "Could not find {0} in the list of your packages".format(
packagename)
+
def retire_package(packagename, branch='devel', allpkgs=False,
username=None, password=None):
"""
12 years, 11 months
[packagedb-cli] No need to query bz if we don't show the output
by Pierre-YvesChibon
commit f85a40f221ceb26a654ee2c7b73b4b68cafbfb35
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Thu Jun 2 11:58:41 2011 +0200
No need to query bz if we don't show the output
pkgdb.py | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index 3e36667..191833c 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -345,14 +345,14 @@ def get_package_info(packagename, branch=None, pending=False,
pkgdbinfo = pkgdbclient.send_request('/acls/name/{0}'.format(packagename),
auth=False)
- log.debug("Query bugzilla")
- bugbz = bzclient.query(
- {'bug_status': ['NEW', 'ASSIGNED', 'NEEDINFO'],
- 'component': packagename})
print pkgdbinfo['title']
if 'packageListings' in pkgdbinfo:
print pkgdbinfo['packageListings'][0]['package']['summary']
if extra:
+ log.debug("Query bugzilla")
+ bugbz = bzclient.query(
+ {'bug_status': ['NEW', 'ASSIGNED', 'NEEDINFO'],
+ 'component': packagename})
print "{0} bugs open (new, assigned, needinfo)".format(len(bugbz))
for collection in pkgdbinfo['packageListings']:
if branch is None or branch == \
12 years, 11 months
[packagedb-cli] Rewrite the orphan action to be able to use basic pattern.
by Pierre-YvesChibon
commit 20372038d4bc2f24b3e0edbdd31ef62421ae49bd
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Thu Jun 2 11:17:17 2011 +0200
Rewrite the orphan action to be able to use basic pattern.
This will enable to do something like:
pkgdb orphan R-\*
or
pkgdb orphan \*bio\*
In order to do this the packagename is transformed into
a real REGEX. "*" are transformed into ".*" and "^" is
added in front while "$" is added behind.
- Add debugging output
pkgdb.py | 35 ++++++++++++++++++++++++-----------
1 files changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index 8ba69d8..3e36667 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -22,6 +22,7 @@ import logging
import getpass
import koji
import sys
+import re
version = '0.0.1'
kojiclient = koji.ClientSession('http://koji.fedoraproject.org/kojihub',
@@ -533,6 +534,7 @@ def orphan_package(packagename, branch='devel', allpkgs=False,
username=None, password=None):
"""
Orphan packages from pkgdb.
+ This implies that the owner is changed to "orphan".
:arg packagename the name of the package to orphan
:kwarg branch the name of the branch to orphan. By default it is
@@ -546,24 +548,32 @@ def orphan_package(packagename, branch='devel', allpkgs=False,
branch = 'devel'
_get_client_authentified(username=username, password=password)
- if allpkgs is True:
- pkgs = get_packager_info(pkgdbclient.username)
-
- for pkg in pkgs:
+ pkgs = get_packager_info(pkgdbclient.username)
+ # transform the packagename to make it a regex
+ motif = "^" + packagename.replace("*",".*") + "$"
+ for pkg in pkgs:
+ if allpkgs is True:
+ log.debug("Orphan all packages")
if branch == "all":
+ log.debug("Orphan in all branches")
branches = _get_active_branches()
for branch in branches:
_orphan_one_package(pkg, branch, username, password)
else:
_orphan_one_package(pkg, branch, username, password)
- else:
- if branch == "all":
- branches = _get_active_branches()
- for branch in branches:
- _orphan_one_package(pkg, branch, username, password)
+ elif re.match(packagename, pkg):
+ log.debug("motif : {0}".format(motif))
+ log.debug("package : {0}".format(pkg))
+ if branch == "all":
+ log.debug("Orphan in all branches")
+ branches = _get_active_branches()
+ for branch in branches:
+ _orphan_one_package(pkg, branch, username, password)
+ else:
+ _orphan_one_package(packagename, branch, username, password)
else:
- _orphan_one_package(packagename, branch, username, password)
-
+ print "Could not find {0} in the list of your packages".format(
+ packagename)
def retire_package(packagename, branch='devel', allpkgs=False,
username=None, password=None):
@@ -586,9 +596,11 @@ def retire_package(packagename, branch='devel', allpkgs=False,
if allpkgs is True:
pkgs = get_packager_info(pkgdbclient.username)
+ log.debug("Retire all packages")
for pkg in pkgs:
if branch == "all":
+ log.debug("Retire in all branches")
branches = _get_active_branches()
for branch in branches:
_orphan_one_package(pkg, branch, username, password)
@@ -596,6 +608,7 @@ def retire_package(packagename, branch='devel', allpkgs=False,
_retire_one_package(pkg, branch, username, password)
else:
if branch == "all":
+ log.debug("Retire in all branches")
branches = _get_active_branches()
for branch in branches:
_orphan_one_package(pkg, branch, username, password)
12 years, 11 months
[packagedb-cli] Print error if message packageid could not be found for a branch
by Pierre-YvesChibon
commit f2ee5284059847355849f4d0c780bf42a6b3dfff
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Thu Jun 2 11:03:12 2011 +0200
Print error if message packageid could not be found for a branch
pkgdb.py | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index 5a42f41..8ba69d8 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -186,12 +186,18 @@ def _retire_one_package(packagename, branch='devel', username=None,
if branch is None:
branch = 'devel'
+
+ log.info("Retiring package {0} on branch {2}".format(packagename,
+ branch))
+
_get_client_authentified(username=username, password=password)
packageid = _get_package_id(packagename, branch)
- log.info("Retiring package {0} ({1}) on branch {2}".format(packagename,
- packageid,
- branch))
+ if packageid is None:
+ print "Cannot retire package {0} on branch {1}, "\
+ "package ID could not be found".format(packagename,
+ branch)
+ return
pkgdbinfo = pkgdbclient.send_request(
'/acls/dispatcher/toggle_retirement',
12 years, 11 months
[packagedb-cli] Implement the logic to orphan/retire all branches
by Pierre-YvesChibon
commit cad3822f4c0bba45f379a5b5147c18e5cff4101b
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Thu Jun 2 10:58:30 2011 +0200
Implement the logic to orphan/retire all branches
pkgdb.py | 20 ++++++++++++--------
1 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/pkgdb.py b/pkgdb.py
index 06a7601..5a42f41 100755
--- a/pkgdb.py
+++ b/pkgdb.py
@@ -545,14 +545,16 @@ def orphan_package(packagename, branch='devel', allpkgs=False,
for pkg in pkgs:
if branch == "all":
- #TODO: implement this feature
- print "logic not implemented yet"
+ branches = _get_active_branches()
+ for branch in branches:
+ _orphan_one_package(pkg, branch, username, password)
else:
_orphan_one_package(pkg, branch, username, password)
else:
if branch == "all":
- #TODO: implement this feature
- print "logic not implemented yet"
+ branches = _get_active_branches()
+ for branch in branches:
+ _orphan_one_package(pkg, branch, username, password)
else:
_orphan_one_package(packagename, branch, username, password)
@@ -581,14 +583,16 @@ def retire_package(packagename, branch='devel', allpkgs=False,
for pkg in pkgs:
if branch == "all":
- #TODO: implement this feature
- print "logic not implemented yet"
+ branches = _get_active_branches()
+ for branch in branches:
+ _orphan_one_package(pkg, branch, username, password)
else:
_retire_one_package(pkg, branch, username, password)
else:
if branch == "all":
- #TODO: implement this feature
- print "logic not implemented yet"
+ branches = _get_active_branches()
+ for branch in branches:
+ _orphan_one_package(pkg, branch, username, password)
else:
_retire_one_package(packagename, branch, username, password)
12 years, 11 months