[sysadmin-bin] Remove the -p option and make use of the positional args, various fixes



commit b079e026899298583917e5836e47d672573b7309
Author: Andrea Veri <av gnome org>
Date:   Mon Jun 8 19:21:51 2015 +0200

    Remove the -p option and make use of the positional args, various fixes

 rpm-signer.py |   36 +++++++++++++++++++-----------------
 1 files changed, 19 insertions(+), 17 deletions(-)
---
diff --git a/rpm-signer.py b/rpm-signer.py
index 2833208..3254320 100755
--- a/rpm-signer.py
+++ b/rpm-signer.py
@@ -8,21 +8,16 @@ import shutil
 import sys
 from optparse import OptionParser
 
-usage = "usage: %prog -c configuration_file [options]"
+usage = "usage: %prog -c configuration_file [-i/-l] [-i/package_name]"
 parser = OptionParser(usage)
 
-
-parser.add_option("-i", "--install",
-                  action="store_true", dest="install",
-                  help="Install and sign a package, requires -p"
-                  )
 parser.add_option("-c", "--config-file",
                   action="store", type ="string", dest="config_file",
                   help="Specify a configuration file"
                   )
-parser.add_option("-p", "--package-name",
-                  action="store", type="string", dest="package_name",
-                  help="The package name you want to install, requires -i"
+parser.add_option("-i", "--install",
+                  action="store_true", dest="install",
+                  help="Install and sign a package, requires -p"
                   )
 parser.add_option("-l", "--list-signatures",
                   action="store_true", dest="list_signatures",
@@ -54,6 +49,10 @@ except ConfigParser.Error:
     sys.exit(1)
 
 def list_rpm_files_signature():
+    if len(args) > 0:
+        print 'No need to specify a package name with the -l option, check --help'
+        sys.exit(1)
+
     for repo in ['el5', 'el6', 'el7']:
         for arch in ['i386', 'x86_64', 'noarch', 'SRPMS']:
             for _file in os.listdir(os.path.join(reposdir, repo, arch)):
@@ -75,13 +74,13 @@ def check_valid_signature(package):
             return False
 
 def sign_rpm(package):
-    package = options.package_name
+    package_name = args[0]
 
     if not os.path.isfile('/usr/bin/rpmsign'):
         print 'The rpmsign binary is not installed, please install the rpm-sign package'
         sys.exit(1)
 
-    query_user = raw_input("Do you want to sign the %s package? Type YES or NO: " % package)
+    query_user = raw_input("Do you want to sign the %s package? Type YES or NO: " % package_name)
 
     if query_user == 'YES' or 'yes':
 
@@ -92,6 +91,7 @@ def sign_rpm(package):
 
         if sign.returncode == 0:
             print 'Package has been signed with the following key: %s' % gpgkeyid
+            print "Run 'cobbler reposync' as root on combobox to regenerate the repositories metadata"
         else:
             error = sign.stderr.readlines()
             report_error = error[1:2]
@@ -102,11 +102,14 @@ def sign_rpm(package):
         print 'Neither "YES" or "NO" were entered, aborting'
 
 def install_package():
-    if not options.package_name:
-        parser.error("No package name was specified, check --help")
+    if len(args) == 0:
+        print 'No package name specified, check --help'
         sys.exit(1)
+    elif len(args) == 1:
+        package = args[0]
+    else:
+        print 'Please list one package at a time'
 
-    package = options.package_name
     packagename_splitted = package.split('.')
 
     for repo in ['el5', 'el6', 'el7']:
@@ -115,7 +118,7 @@ def install_package():
                 if arch in packagename_splitted:
                     dest = os.path.join(reposdir, repo, arch)
 
-                    if os.path.isdir(dest):
+                    if os.path.isdir(dest) and os.path.isfile(package):
                         print 'Copying %s to %s' % (package, dest) + '\n'
                         shutil.copy(package, dest)
 
@@ -123,9 +126,8 @@ def install_package():
                         if os.path.isfile(newdest):
                             print '%s has been copied, now signing it' % package + '\n'
                             sign_rpm(newdest)
-                            print "Run 'cobbler reposync' as root on combobox to regenerate the repositories 
metadata"
                     else:
-                        print 'No such directory: %s, please make sure the path actually exists' % dest
+                        print "Either %s or the RPM file you want to install couldn't be found" % dest
                         sys.exit(1)
 
 def main():


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]