|
|
85a850 |
'''
|
|
|
85a850 |
The main behavior of centpkg
|
|
|
85a850 |
'''
|
|
|
85a850 |
#
|
|
|
85a850 |
# Author(s):
|
|
|
85a850 |
# Jesse Keating <jkeating@redhat.com>
|
|
|
85a850 |
# Pat Riehecky <riehecky@fnal.gov>
|
|
|
85a850 |
# Brian Stinson <bstinson@ksu.edu>
|
|
|
85a850 |
#
|
|
|
85a850 |
# This program is free software; you can redistribute it and/or modify it
|
|
|
85a850 |
# under the terms of the GNU General Public License as published by the
|
|
|
85a850 |
# Free Software Foundation; either version 2 of the License, or (at your
|
|
|
85a850 |
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
|
|
|
85a850 |
# the full text of the license.
|
|
|
85a850 |
|
|
|
85a850 |
import os
|
|
|
85a850 |
import sys
|
|
|
85a850 |
import logging
|
|
|
85a850 |
import ConfigParser
|
|
|
85a850 |
import argparse
|
|
|
85a850 |
|
|
|
85a850 |
import pyrpkg
|
|
|
85a850 |
import centpkg
|
|
|
85a850 |
|
|
|
85a850 |
def main():
|
|
|
85a850 |
'''
|
|
|
85a850 |
Where things actually happen
|
|
|
85a850 |
'''
|
|
|
85a850 |
parser = argparse.ArgumentParser(add_help=False)
|
|
|
85a850 |
parser.add_argument('-C', '--config', help='The rpkg config file to use',
|
|
|
85a850 |
default='/etc/rpkg/centpkg.conf')
|
|
|
85a850 |
|
|
|
85a850 |
(args, other) = parser.parse_known_args()
|
|
|
85a850 |
|
|
|
85a850 |
# Make sure we have a sane config file
|
|
|
85a850 |
if not os.path.exists(args.config) and not other[-1] in ['--help', '-h']:
|
|
|
85a850 |
sys.stderr.write('Invalid config file %s\n' % args.config)
|
|
|
85a850 |
sys.exit(1)
|
|
|
85a850 |
|
|
|
85a850 |
config = ConfigParser.SafeConfigParser()
|
|
|
85a850 |
config.read(args.config)
|
|
|
85a850 |
|
|
|
85a850 |
client = centpkg.cli.centpkgClient(config)
|
|
|
85a850 |
client.do_imports(site='centpkg')
|
|
|
85a850 |
client.parse_cmdline()
|
|
|
85a850 |
|
|
|
85a850 |
if not client.args.path:
|
|
|
85a850 |
try:
|
|
|
85a850 |
client.args.path = os.getcwd()
|
|
|
85a850 |
except OSError as err_msg:
|
|
|
85a850 |
print('Could not get current path')
|
|
|
85a850 |
print(err_msg)
|
|
|
85a850 |
sys.exit(1)
|
|
|
85a850 |
|
|
|
85a850 |
log = pyrpkg.log
|
|
|
85a850 |
client.setupLogging(log)
|
|
|
85a850 |
|
|
|
85a850 |
if client.args.v:
|
|
|
85a850 |
log.setLevel(logging.DEBUG)
|
|
|
85a850 |
elif client.args.q:
|
|
|
85a850 |
log.setLevel(logging.WARNING)
|
|
|
85a850 |
else:
|
|
|
85a850 |
log.setLevel(logging.INFO)
|
|
|
85a850 |
|
|
|
85a850 |
# Run the necessary command
|
|
|
85a850 |
try:
|
|
|
85a850 |
sys.exit(client.args.command())
|
|
|
85a850 |
except KeyboardInterrupt:
|
|
|
85a850 |
pass
|
|
Brian Stinson |
13c432 |
except Exception, e:
|
|
Brian Stinson |
13c432 |
log.error('Could not execute %s: %s' % (client.args.command.__name__, e))
|
|
Brian Stinson |
13c432 |
sys.exit(1)
|
|
|
85a850 |
|
|
|
85a850 |
if __name__ == '__main__':
|
|
|
85a850 |
main()
|