invirt-quota: fix imports EIBTI-style
[invirt/packages/invirt-database.git] / scripts / invirt-quota
index 8a7f67c..22c663a 100755 (executable)
@@ -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 <owner> [options]',
+    parser = optparse.OptionParser(usage = '%prog <owner> [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))