From: Greg Price Date: Fri, 27 Feb 2009 07:56:41 +0000 (-0500) Subject: invirt-quota: fix imports EIBTI-style X-Git-Tag: 0.1.8~3 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-database.git/commitdiff_plain/6dc450951772a078d728538a24006896112bfefb?hp=f27d53bc4beda55662917856b1b7ca8321f72e3b invirt-quota: fix imports EIBTI-style also needn't call int() on value from optparse svn path=/trunk/packages/invirt-database/; revision=2198 --- diff --git a/debian/changelog b/debian/changelog index 6ff546e..d187a03 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,8 +13,9 @@ invirt-database (0.1.8) unstable; urgency=low invirt-quota: * refactor code that sets values * print full help on no arguments + * make EIBTI imports - -- Greg Price Thu, 26 Feb 2009 22:51:43 -0500 + -- Greg Price Fri, 27 Feb 2009 02:16:28 -0500 invirt-database (0.1.7) unstable; urgency=low diff --git a/scripts/invirt-quota b/scripts/invirt-quota index 8a7f67c..22c663a 100755 --- a/scripts/invirt-quota +++ b/scripts/invirt-quota @@ -6,12 +6,13 @@ for an owner. Invoking with only an owner name returns the current quotas for that owner. Setting a parameter to -1 restores the default. """ -from invirt.database import * -from sys import argv, exit, stderr, stdout -from optparse import OptionParser +import sys +import optparse + +from invirt import database def main(argv): - parser = OptionParser(usage = '%prog [options]', + parser = optparse.OptionParser(usage = '%prog [options]', description = __doc__.strip()) parser.add_option('-m', '--ram-total', type = 'int', @@ -40,27 +41,26 @@ def main(argv): opts, args = parser.parse_args() if len(args) != 1: - parser.print_help(stderr) + parser.print_help(sys.stderr) return 1 owner = args[0] - connect() - session.begin() + database.connect() + database.session.begin() - x = Owner.query().filter_by(owner_id=owner).first() + x = database.Owner.query().filter_by(owner_id=owner).first() if x is None: - x = Owner(owner_id=owner) + x = database.Owner(owner_id=owner) for resource, scope in [('ram', 'total'), ('ram', 'single'), ('disk', 'total'), ('disk', 'single'), ('vms', 'total'), ('vms', 'active')]: - opt = getattr(opts, resource+scope) - if opt is not None: - val = int(opt) + val = getattr(opts, resource+scope) + if val is not None: setattr(x, resource+'_quota_'+scope, val if val >= 0 else None) - session.commit() + database.session.commit() print str(x) return 0 if __name__ == '__main__': - exit(main(argv)) + sys.exit(main(sys.argv))