mirror of
https://git.centos.org/centos/centpkg.git
synced 2025-02-23 16:22:55 +00:00
Looks good to me! I'm eager to hear back from upstream about your patches.
Merged in jcpunk/centpkg (pull request #1) Mostly changes to keep this closer to the fedpkg codebase - not terribly many
This commit is contained in:
commit
d16bf371a2
4 changed files with 203 additions and 131 deletions
|
@ -1,57 +1,20 @@
|
|||
#!/usr/bin/env python
|
||||
import pdb
|
||||
'''
|
||||
centpkg - a script to interact with CentOS Packages
|
||||
'''
|
||||
#
|
||||
# Author(s):
|
||||
# Brian Stinson <bstinson@ksu.edu>
|
||||
# Pat Riehecky <riehecky@fnal.gov>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 2 of the License, or (at your
|
||||
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
|
||||
# the full text of the license.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import ConfigParser
|
||||
import argparse
|
||||
from centpkg.__main__ import main
|
||||
|
||||
import pyrpkg
|
||||
import centpkg
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(add_help=False)
|
||||
parser.add_argument('-C','--config', help='The rpkg config file to use',
|
||||
default='/etc/rpkg/centpkg.conf')
|
||||
|
||||
(args, other) = parser.parse_known_args()
|
||||
|
||||
# Make sure we have a sane config file
|
||||
if not os.path.exists(args.config) and not other[-1] in ['--help', '-h']:
|
||||
sys.stderr.write('Invalid config file %s\n' % args.config)
|
||||
sys.exit(1)
|
||||
|
||||
config = ConfigParser.SafeConfigParser()
|
||||
config.read(args.config)
|
||||
|
||||
client = centpkg.cli.centpkgClient(config)
|
||||
client.do_imports(site='centpkg')
|
||||
client.parse_cmdline()
|
||||
|
||||
if not client.args.path:
|
||||
try:
|
||||
client.args.path=os.getcwd()
|
||||
except:
|
||||
print('Could not get current path')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
log = pyrpkg.log
|
||||
client.setupLogging(log)
|
||||
|
||||
if client.args.v:
|
||||
log.setLevel(logging.DEBUG)
|
||||
elif client.args.q:
|
||||
log.setLevel(logging.WARNING)
|
||||
else:
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
# Run the necessary command
|
||||
try:
|
||||
sys.exit(client.args.command())
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
#pylint: disable=line-too-long,abstract-class-not-used
|
||||
'''
|
||||
Top level function library for centpkg
|
||||
'''
|
||||
#
|
||||
# Author(s):
|
||||
# Jesse Keating <jkeating@redhat.com>
|
||||
# Pat Riehecky <riehecky@fnal.gov>
|
||||
# Brian Stinson <bstinson@ksu.edu>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 2 of the License, or (at your
|
||||
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
|
||||
# the full text of the license.
|
||||
|
||||
|
||||
|
||||
import pyrpkg
|
||||
import os
|
||||
import re
|
||||
|
@ -5,20 +23,26 @@ import re
|
|||
from . import cli
|
||||
|
||||
class Commands(pyrpkg.Commands):
|
||||
'''
|
||||
For the pyrpkg commands with centpkg behavior
|
||||
'''
|
||||
def __init__(self, path, lookaside, lookasidehash, lookaside_cgi,
|
||||
gitbaseurl, anongiturl, branchre, kojiconfig,
|
||||
build_client, user=None, dist=None, target=None,
|
||||
quiet=False):
|
||||
|
||||
'''
|
||||
Init the object and some configuration details.
|
||||
'''
|
||||
super(Commands, self).__init__(path, lookaside, lookasidehash,
|
||||
lookaside_cgi, gitbaseurl, anongiturl,
|
||||
branchre, kojiconfig, build_client,
|
||||
user, dist, target,
|
||||
quiet)
|
||||
|
||||
user, dist, target, quiet)
|
||||
|
||||
# redefined loaders
|
||||
def load_rpmdefines(self):
|
||||
'''
|
||||
Populate rpmdefines based on branch data
|
||||
'''
|
||||
try:
|
||||
osver = re.search(r'\d.*$', self.branch_merge).group()
|
||||
except AttributeError:
|
||||
|
@ -41,15 +65,76 @@ class Commands(pyrpkg.Commands):
|
|||
# Get a list of files in the path we're looking at
|
||||
files = os.listdir(os.path.join(self.path,'SPECS'))
|
||||
# Search the files for the first one that ends with ".spec"
|
||||
for f in files:
|
||||
if f.endswith('.spec') and not f.startswith('.'):
|
||||
self._spec = os.path.join('SPECS',f)
|
||||
for __f in files:
|
||||
if __f.endswith('.spec') and not __f.startswith('.'):
|
||||
self._spec = os.path.join('SPECS', __f)
|
||||
return
|
||||
|
||||
raise pyrpkg.rpkgError('No spec file found.')
|
||||
|
||||
# These are the commands defined in the base pyrpkg.Commands class
|
||||
# and have been implemented here
|
||||
def clone(self, *args, **kwargs):
|
||||
super(Commands, self).clone(*args, **kwargs)
|
||||
|
||||
def sources(self, outdir=None):
|
||||
"""Download source files"""
|
||||
|
||||
# in 'super' the sources function expects a file named 'sources' to be in the base directory.
|
||||
# A patch has been sent to upstream to allow a more flexible location.
|
||||
#
|
||||
# This code doesn't work due to:
|
||||
# archive.strip().split(' ', 1) # patch provided to upstream to fix
|
||||
#
|
||||
# url = '%s/%s/%s/%s/%s' % (self.lookaside, self.module_name,
|
||||
# file.replace(' ', '%20'),
|
||||
# csum, file.replace(' ', '%20'))
|
||||
#
|
||||
#os.symlink(os.path.join(self.path, '.{0}.metadata'.format(self.module_name)), os.path.join(self.path, 'sources'))
|
||||
#super(Commands, self).sources(outdir=None)
|
||||
#os.unlink(os.path.join(self.path, 'sources'))
|
||||
|
||||
# The following is copied from rpkg/__init__.py:sources with minor changes
|
||||
try:
|
||||
archives = open(os.path.join(self.path,
|
||||
'.{0}.metadata'.format(self.module_name)),
|
||||
'r').readlines()
|
||||
except IOError, e:
|
||||
raise pyrpkg.rpkgError('%s is not a valid repo: %s' % (self.path, e))
|
||||
# Default to putting the files where the module is
|
||||
if not outdir:
|
||||
outdir = self.path
|
||||
for archive in archives:
|
||||
try:
|
||||
# This strip / split is kind a ugly, but checksums shouldn't have
|
||||
# two spaces in them. sources file might need more structure in the
|
||||
# future
|
||||
csum, file = archive.strip().split(None, 1)
|
||||
except ValueError:
|
||||
raise pyrpkg.rpkgError('Malformed sources file.')
|
||||
# See if we already have a valid copy downloaded
|
||||
outfile = os.path.join(outdir, file)
|
||||
if os.path.exists(outfile):
|
||||
if self._verify_file(outfile, csum, self.lookasidehash):
|
||||
continue
|
||||
self.log.info("Downloading %s" % (file))
|
||||
url = '%s/%s/%s/%s' % (self.lookaside, self.module_name,
|
||||
self.branch_merge,
|
||||
csum,
|
||||
)
|
||||
command = ['curl', '-H', 'Pragma:', '-o', outfile, '-R', '-S', '--fail']
|
||||
if self.quiet:
|
||||
command.append('-s')
|
||||
command.append(url)
|
||||
self._run_command(command)
|
||||
if not self._verify_file(outfile, csum, self.lookasidehash):
|
||||
raise pyrpkg.rpkgError('%s failed checksum' % file)
|
||||
|
||||
return
|
||||
|
||||
# These are the commands defined in the base pyrpkg.Commands class
|
||||
# and have not been implemented here, yet
|
||||
|
||||
def load_kojisession(self, *args, **kwargs):
|
||||
raise NotImplementedError("This command is not yet implemented in centpkg")
|
||||
|
||||
|
@ -59,9 +144,6 @@ class Commands(pyrpkg.Commands):
|
|||
def clean(self, *args, **kwargs):
|
||||
raise NotImplementedError("This command is not yet implemented in centpkg")
|
||||
|
||||
def clone(self, *args, **kwargs):
|
||||
super(Commands,self).clone(*args, **kwargs)
|
||||
|
||||
def clone_with_dirs(self, *args, **kwargs):
|
||||
raise NotImplementedError("This command is not yet implemented in centpkg")
|
||||
|
||||
|
@ -95,70 +177,6 @@ class Commands(pyrpkg.Commands):
|
|||
def push(self, *args, **kwargs):
|
||||
raise NotImplementedError("This command is not yet implemented in centpkg")
|
||||
|
||||
def sources(self, outdir=None):
|
||||
"""Download source files"""
|
||||
|
||||
# We are not using sources() in super because the metadata file is
|
||||
# hard-coded into the first open() call. Otherwise this is copied from
|
||||
# upstream pyrpkg
|
||||
|
||||
try:
|
||||
archives = open(os.path.join(self.path,
|
||||
'.{0}.metadata'.format(self.module_name)),
|
||||
'r').readlines()
|
||||
except IOError, e:
|
||||
raise pyrpkg.rpkgError('%s is not a valid repo: %s' % (self.path, e))
|
||||
# Default to putting the files where the module is
|
||||
if not outdir:
|
||||
outdir = self.path
|
||||
for archive in archives:
|
||||
try:
|
||||
# This strip / split is kind a ugly, but checksums shouldn't have
|
||||
# two spaces in them. sources file might need more structure in the
|
||||
# future
|
||||
csum, file = archive.strip().split(None, 1)
|
||||
except ValueError:
|
||||
raise pyrpkg.rpkgError('Malformed sources file.')
|
||||
# See if we already have a valid copy downloaded
|
||||
outfile = os.path.join(outdir, file)
|
||||
if os.path.exists(outfile):
|
||||
if self._verify_file(outfile, csum, self.lookasidehash):
|
||||
continue
|
||||
self.log.info("Downloading %s" % (file))
|
||||
url = '%s/%s/%s/%s' % (self.lookaside, self.module_name,
|
||||
self.branch_merge,
|
||||
csum,
|
||||
)
|
||||
# There is some code here for using pycurl, but for now,
|
||||
# just use subprocess
|
||||
#output = open(file, 'wb')
|
||||
#curl = pycurl.Curl()
|
||||
#curl.setopt(pycurl.URL, url)
|
||||
#curl.setopt(pycurl.FOLLOWLOCATION, 1)
|
||||
#curl.setopt(pycurl.MAXREDIRS, 5)
|
||||
#curl.setopt(pycurl.CONNECTTIMEOUT, 30)
|
||||
#curl.setopt(pycurl.TIMEOUT, 300)
|
||||
#curl.setopt(pycurl.WRITEDATA, output)
|
||||
#try:
|
||||
# curl.perform()
|
||||
#except:
|
||||
# print "Problems downloading %s" % url
|
||||
# curl.close()
|
||||
# output.close()
|
||||
# return 1
|
||||
#curl.close()
|
||||
#output.close()
|
||||
# These options came from Makefile.common.
|
||||
# Probably need to support wget as well
|
||||
command = ['curl', '-H', 'Pragma:', '-o', outfile, '-R', '-S', '--fail']
|
||||
if self.quiet:
|
||||
command.append('-s')
|
||||
command.append(url)
|
||||
self._run_command(command)
|
||||
if not self._verify_file(outfile, csum, self.lookasidehash):
|
||||
raise pyrpkg.rpkgError('%s failed checksum' % file)
|
||||
return
|
||||
|
||||
def switch_branch(self, *args, **kwargs):
|
||||
raise NotImplementedError("This command is not yet implemented in centpkg")
|
||||
|
||||
|
|
72
src/centpkg/__main__.py
Normal file
72
src/centpkg/__main__.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
'''
|
||||
The main behavior of centpkg
|
||||
'''
|
||||
#
|
||||
# Author(s):
|
||||
# Jesse Keating <jkeating@redhat.com>
|
||||
# Pat Riehecky <riehecky@fnal.gov>
|
||||
# Brian Stinson <bstinson@ksu.edu>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 2 of the License, or (at your
|
||||
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
|
||||
# the full text of the license.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import ConfigParser
|
||||
import argparse
|
||||
|
||||
import pyrpkg
|
||||
import centpkg
|
||||
|
||||
def main():
|
||||
'''
|
||||
Where things actually happen
|
||||
'''
|
||||
parser = argparse.ArgumentParser(add_help=False)
|
||||
parser.add_argument('-C', '--config', help='The rpkg config file to use',
|
||||
default='/etc/rpkg/centpkg.conf')
|
||||
|
||||
(args, other) = parser.parse_known_args()
|
||||
|
||||
# Make sure we have a sane config file
|
||||
if not os.path.exists(args.config) and not other[-1] in ['--help', '-h']:
|
||||
sys.stderr.write('Invalid config file %s\n' % args.config)
|
||||
sys.exit(1)
|
||||
|
||||
config = ConfigParser.SafeConfigParser()
|
||||
config.read(args.config)
|
||||
|
||||
client = centpkg.cli.centpkgClient(config)
|
||||
client.do_imports(site='centpkg')
|
||||
client.parse_cmdline()
|
||||
|
||||
if not client.args.path:
|
||||
try:
|
||||
client.args.path = os.getcwd()
|
||||
except OSError as err_msg:
|
||||
print('Could not get current path')
|
||||
print(err_msg)
|
||||
sys.exit(1)
|
||||
|
||||
log = pyrpkg.log
|
||||
client.setupLogging(log)
|
||||
|
||||
if client.args.v:
|
||||
log.setLevel(logging.DEBUG)
|
||||
elif client.args.q:
|
||||
log.setLevel(logging.WARNING)
|
||||
else:
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
# Run the necessary command
|
||||
try:
|
||||
sys.exit(client.args.command())
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,12 +1,30 @@
|
|||
'''
|
||||
Command line behavior for centpkg
|
||||
'''
|
||||
#
|
||||
# Author(s):
|
||||
# Jesse Keating <jkeating@redhat.com>
|
||||
# Pat Riehecky <riehecky@fnal.gov>
|
||||
# Brian Stinson <bstinson@ksu.edu>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 2 of the License, or (at your
|
||||
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
|
||||
# the full text of the license.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
|
||||
from pyrpkg.cli import cliClient
|
||||
|
||||
|
||||
class centpkgClient(cliClient):
|
||||
'''
|
||||
Where we import our custom stuff
|
||||
'''
|
||||
def __init__(self, config, name='centpkg'):
|
||||
'''init'''
|
||||
super(centpkgClient, self).__init__(config, name)
|
||||
|
||||
|
||||
|
@ -18,8 +36,9 @@ if __name__ == '__main__':
|
|||
if not client.args.path:
|
||||
try:
|
||||
client.args.path = os.getcwd()
|
||||
except:
|
||||
except OSError as err_msg:
|
||||
print('Could not get current path')
|
||||
print(err_msg)
|
||||
sys.exit(1)
|
||||
|
||||
log = client.site.log
|
||||
|
|
Loading…
Add table
Reference in a new issue