summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhishek Mukherjee <linkinpark342@gmail.com>2009-02-08 01:15:40 -0500
committerAbhishek Mukherjee <linkinpark342@gmail.com>2009-02-08 01:17:23 -0500
commitb2b9dadea47308390a6fc11a35476e25100710fd (patch)
treef4e1a5f2fb83b1375cedd24ae9bdc40dee7fe9cc
parent788f981bc67940fda178b92826a1e2517d829fad (diff)
downloadrpmbuild-remote-b2b9dadea47308390a6fc11a35476e25100710fd.tar.gz
rpmbuild-remote-b2b9dadea47308390a6fc11a35476e25100710fd.tar.xz
rpmbuild-remote-b2b9dadea47308390a6fc11a35476e25100710fd.zip
Migrate to optparse
-rw-r--r--rpmbuild-remote.py98
1 files changed, 38 insertions, 60 deletions
diff --git a/rpmbuild-remote.py b/rpmbuild-remote.py
index ca2ae87..f24cb8c 100644
--- a/rpmbuild-remote.py
+++ b/rpmbuild-remote.py
@@ -4,71 +4,49 @@
from iniparse import INIConfig
import logging
import paramiko
-import getopt
+import optparse
import sys
import os
-def usage():
- print """
-rpmbuild-remote : Build an RPM on a remote system
-
- rpmbuild-remote [options]... <files>...
-
- --help Print this message
- -c, --config <config> Configuration file to use for the build.
- Default: ~/.rpmbuild-remote
- -s, --system <system> The remote machine to use (defined in config
- file)
- -u, --user <username> The username on the remote system
- Default: current user
- -h, --host <host> The hostname/IP of the remote system
- -p, --port <port> The port to use on the remote system
- Default: 21
- -d, --dest <dest> Directory to place resulting files
- Default: ~/rpmbuild-remote/
- -m, --mock <target> Use mock (only applies to SRPM files)
- Default: No mock builds (uses rpmbuild --rebuild
- otherwise)
- files The list of files can contain either SRPM
- files or a list starting with a spec file and
- followed by sources for the package.
-"""
+def get_parser():
+ """Return a commandline parser"""
+ parser = optparse.OptionParser(usage="%prog [options]... <files>...")
+ home=os.path.expanduser("~")
+ parser.set_conflict_handler("resolve")
+ parser.add_option("-c", "--config",
+ action="store", type="string", dest="config",
+ default=os.path.join(home,".rpmbuild-remote"),
+ help="Configuration file to use for the build. "
+ "[Default: ~/.rpmbuild-remote")
+ parser.add_option("-s", "--system",
+ action="store", type="string", dest="system",
+ help="The remote machine to use (defined in config file)")
+ parser.add_option("-u", "--user",
+ action="store", type="string", dest="user",
+ default=os.getlogin(),
+ help="The username on the remote system [Default: current user]")
+ parser.add_option("-h", "--host",
+ action="store", type="string", dest="host",
+ help="The hostname/IP of the remote system")
+ parser.add_option("-p", "--port",
+ action="store", type="int", dest="port",
+ default=21,
+ help="The port to use on the remote system [Default: 21")
+ parser.add_option("-d", "--dest",
+ action="store", type="string", dest="dest",
+ default=os.path.join(home, "rpmbuild-remote"),
+ help="Directory to place resulting files "
+ "[Default: ~/rpmbuild-remote/]")
+ parser.add_option("-m", "--mock",
+ action="store", type="string", dest="mock",
+ default=None,
+ help="Use mock (only applies to SRPM files) [Default: No mock "
+ "builds (uses rpmbuild --rebuild otherwise)]")
+ return parser
def main(argv):
- try:
- opts, args = getopts.getopts(argv, "c:s:u:h:p:d:m:", ['config=', 'system=', 'user=', 'host=', 'port=', 'dest=', 'mock='])
- except getopt.GetoptError, err:
- print str(err)
- usage()
- sys.exit(1)
- log = logging.getLogger('rpmbuild-remote')
- home = os.path.expanduser('~')
- config = os.path.join(home, '.rpmbuild-remote')
- system = ''
- user = os.getlogin()
- host = ''
- port = 21
- dest = os.path.join(home, 'rpmbuild-remote')
- mock = ''
- jobs = []
- for opt, val in opts:
- if opt in ['c', 'config']:
- config = val
- elif opt in ['s', 'system']:
- system = val
- elif opt in ['u', 'user']:
- user = val
- elif opt in ['h', 'host']:
- host = val
- elif opt in ['p', 'port']:
- port = val
- elif opt in ['d', 'dest']:
- dest = val
- elif opt in ['m', 'mock']:
- mock = val
- elif opt in ['help']:
- usage()
- sys.exit(0)
+ parser = get_parser()
+ opts, args = parser.parse_args()
for arg in args:
ext = arg.split('.')[-1]
if ext == 'srpm':