Skip to content

Commit

Permalink
Uppercase global CONFIG
Browse files Browse the repository at this point in the history
There was an overloaded use of cf within classes and this makes that
distinction clearer.
  • Loading branch information
jrha committed Jul 15, 2024
1 parent e9e94c9 commit 4c25138
Showing 1 changed file with 71 additions and 71 deletions.
142 changes: 71 additions & 71 deletions mrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def writesha1(self):
def lock(self, action):
if OPTIONS.dryrun:
return True
lockfile = os.path.join(cf.lockdir, self.dist.nick, action + '-' + self.name + '.lock')
lockfile = os.path.join(CONFIG.lockdir, self.dist.nick, action + '-' + self.name + '.lock')
mkdir(os.path.dirname(lockfile))
try:
fd = os.open(lockfile, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0600)
Expand Down Expand Up @@ -583,7 +583,7 @@ def lock(self, action):
def unlock(self, action):
if OPTIONS.dryrun:
return True
lockfile = os.path.join(cf.lockdir, self.dist.nick, action + '-' + self.name + '.lock')
lockfile = os.path.join(CONFIG.lockdir, self.dist.nick, action + '-' + self.name + '.lock')
info(6, '%s: Removing lock %s' % (self.dist.nick, lockfile))
if os.path.exists(lockfile):
pid = open(lockfile).read()
Expand Down Expand Up @@ -619,12 +619,12 @@ def createmd(self):

def repomd(self):
"Create a repomd repository"
if not cf.cmd['createrepo']:
if not CONFIG.cmd['createrepo']:
raise mrepoGenerateException('Command createrepo is not found. Skipping.')

groupfilename = 'comps.xml'

opts = ' ' + cf.createrepooptions
opts = ' ' + CONFIG.createrepooptions
if OPTIONS.force:
opts = ' --pretty' + opts
if OPTIONS.verbose <= 2:
Expand All @@ -635,20 +635,20 @@ def repomd(self):
opts = opts + ' -n'
if os.path.isdir(self.wwwdir):
repoopts = opts
if cf.cachedir:
cachedir = os.path.join(cf.cachedir, self.dist.nick, self.name)
if CONFIG.cachedir:
cachedir = os.path.join(CONFIG.cachedir, self.dist.nick, self.name)
mkdir(cachedir)
repoopts = repoopts + ' --cachedir "%s"' % cachedir
if os.path.isdir(os.path.join(self.wwwdir, '.olddata')):
remove(os.path.join(self.wwwdir, '.olddata'))
groupfile = os.path.join(cf.srcdir, self.dist.nick, self.name + '-comps.xml')
groupfile = os.path.join(CONFIG.srcdir, self.dist.nick, self.name + '-comps.xml')
if os.path.isfile(groupfile):
symlink(groupfile, os.path.join(self.wwwdir, 'comps.xml'))
repoopts = repoopts + ' --groupfile "%s"' % groupfile
info(2, '%s: Create repomd repository for %s' % (self.dist.nick, self.name))
ret = run('%s %s %s' % (cf.cmd['createrepo'], repoopts, self.wwwdir))
ret = run('%s %s %s' % (CONFIG.cmd['createrepo'], repoopts, self.wwwdir))
if ret:
raise mrepoGenerateException('%s failed with return code: %s' % (cf.cmd['createrepo'], ret))
raise mrepoGenerateException('%s failed with return code: %s' % (CONFIG.cmd['createrepo'], ret))


class mrepoMirrorException(Exception):
Expand Down Expand Up @@ -880,7 +880,7 @@ def mkdir(path):

def mirrorrsync(url, path):
"Mirror everything from an rsync:// URL"
if not cf.cmd['rsync']:
if not CONFIG.cmd['rsync']:
error(1, 'rsync was not found. rsync support is therefore disabled.')
return

Expand All @@ -890,7 +890,7 @@ def mirrorrsync(url, path):

mkdir(path)

opts = cf.rsyncoptions
opts = CONFIG.rsyncoptions
if OPTIONS.verbose <= 2:
opts = opts + ' -q'
elif OPTIONS.verbose == 3:
Expand All @@ -903,37 +903,37 @@ def mirrorrsync(url, path):
opts = opts + ' -vvv --progress'
if OPTIONS.dryrun:
opts = opts + ' --dry-run'
if cf.rsynctimeout:
opts = opts + ' --timeout=%s' % cf.rsynctimeout
if cf.rsynccleanup:
if CONFIG.rsynctimeout:
opts = opts + ' --timeout=%s' % CONFIG.rsynctimeout
if CONFIG.rsynccleanup:
opts = opts + ' --delete-after --delete-excluded'
if cf.rsyncbwlimit:
opts = opts + ' --bwlimit=%s' % cf.rsyncbwlimit
if cf.rsyncexclheaders:
if CONFIG.rsyncbwlimit:
opts = opts + ' --bwlimit=%s' % CONFIG.rsyncbwlimit
if CONFIG.rsyncexclheaders:
opts = opts + ' --exclude=\"/headers/\"'
if cf.rsyncexclrepodata:
if CONFIG.rsyncexclrepodata:
opts = opts + ' --exclude=\"/repodata/\"'
if cf.rsyncexclsrpm:
if CONFIG.rsyncexclsrpm:
opts = opts + ' --exclude=\"*.src.rpm\" --exclude=\"/SRPMS/\"'
if cf.rsyncexcldebug:
if CONFIG.rsyncexcldebug:
opts = opts + ' --exclude=\"*-debuginfo-*.rpm\" --exclude=\"/debug/\"'
opts = opts + ' --include=\"*.rpm\"'
if cf.rsyncexclsrpm or cf.rsyncexcldebug:
if CONFIG.rsyncexclsrpm or CONFIG.rsyncexcldebug:
opts = opts + ' --exclude=\"*.*\"'

ret = run('%s %s %s %s' % (cf.cmd['rsync'], opts, url, path), dryrun=True)
ret = run('%s %s %s %s' % (CONFIG.cmd['rsync'], opts, url, path), dryrun=True)
if ret:
raise mrepoMirrorException('Failed with return code: %s' % ret)


def mirrorlftp(url, path, dist):
"Mirror everything from a http://, ftp://, sftp://, fish:// URL"
if not cf.cmd['lftp']:
if not CONFIG.cmd['lftp']:
error(1, 'lftp was not found. fish, ftp, http and sftp support (using lftp) is therefore disabled.')
return
mkdir(path)

cmds = cf.lftpcommands + ';'
cmds = CONFIG.lftpcommands + ';'

if dist.sslcert:
cmds = cmds + ' set ssl:cert-file ' + dist.sslcert + ';'
Expand All @@ -942,36 +942,36 @@ def mirrorlftp(url, path, dist):
if dist.sslca:
cmds = cmds + ' set ssl:ca-file ' + dist.sslca + ' ;'

if cf.lftptimeout:
cmds = cmds + ' set net:timeout %s;' % cf.lftptimeout
if cf.lftpbwlimit:
cmds = cmds + ' set net:limit-total-rate %s:0;' % cf.lftpbwlimit
if CONFIG.lftptimeout:
cmds = cmds + ' set net:timeout %s;' % CONFIG.lftptimeout
if CONFIG.lftpbwlimit:
cmds = cmds + ' set net:limit-total-rate %s:0;' % CONFIG.lftpbwlimit

opts = cf.lftpoptions
opts = CONFIG.lftpoptions
if OPTIONS.verbose >= 6:
opts = opts + ' -d'

mirroropts = cf.lftpmirroroptions
mirroropts = CONFIG.lftpmirroroptions
if OPTIONS.verbose >= 3:
mirroropts = mirroropts + ' -v' * (OPTIONS.verbose - 2)
if OPTIONS.dryrun:
mirroropts = mirroropts + ' --dry-run'
if cf.lftpcleanup:
if CONFIG.lftpcleanup:
mirroropts = mirroropts + ' -e'
mirroropts = mirroropts + ' -I *.rpm -X \"/headers/\" -X \"/repodata/\"'
if cf.lftpexclsrpm:
if CONFIG.lftpexclsrpm:
mirroropts = mirroropts + ' -X \"*.src.rpm\" -X \"/SRPMS/\"'
if cf.lftpexcldebug:
if CONFIG.lftpexcldebug:
mirroropts = mirroropts + ' -X \"*-debuginfo-*.rpm\" -X \"/debug/\"'

ret = run('%s %s -c \'%s mirror %s %s %s\'' % (cf.cmd['lftp'], opts, cmds, mirroropts, url, path), dryrun=True)
ret = run('%s %s -c \'%s mirror %s %s %s\'' % (CONFIG.cmd['lftp'], opts, cmds, mirroropts, url, path), dryrun=True)
if ret:
raise mrepoMirrorException('Failed with return code: %s' % ret)


def mirrorreposync(url, path, reponame, dist):
"Mirror everything from a reposync:// URL"
if not cf.cmd['reposync']:
if not CONFIG.cmd['reposync']:
error(1, 'reposync was not found. reposync support is therefore disabled.')
return
mkdir(path)
Expand All @@ -980,21 +980,21 @@ def mirrorreposync(url, path, reponame, dist):
url = url.replace('reposync://', 'http://')
url = url.replace('reposyncf://', 'ftp://')

if cf.reposyncexcldebug:
if CONFIG.reposyncexcldebug:
reposync_exclude = "*-debuginfo"
else:
reposync_exclude = ""

opts = cf.reposyncoptions
opts = CONFIG.reposyncoptions
if OPTIONS.verbose < 3:
opts = opts + ' -q'
if OPTIONS.dryrun:
opts = opts + ' --urls'
if cf.reposynccleanup:
if CONFIG.reposynccleanup:
opts = opts + ' --delete'
if cf.reposyncnewestonly:
if CONFIG.reposyncnewestonly:
opts = opts + ' --newest-only'
if cf.reposyncnorepopath:
if CONFIG.reposyncnorepopath:
opts = opts + ' --norepopath'

# store a temporary YUM config to use with reposync
Expand All @@ -1008,10 +1008,10 @@ def mirrorreposync(url, path, reponame, dist):
reposync_conf_contents += "sslclientcert=%s\n" % dist.sslcert
if dist.sslkey:
reposync_conf_contents += "sslclientkey=%s\n" % dist.sslkey
if cf.reposynctimeout:
reposync_conf_contents += "timeout=%s\n" % cf.reposynctimeout
if cf.reposyncminrate:
reposync_conf_contents += "minrate=%s\n" % cf.reposyncminrate
if CONFIG.reposynctimeout:
reposync_conf_contents += "timeout=%s\n" % CONFIG.reposynctimeout
if CONFIG.reposyncminrate:
reposync_conf_contents += "minrate=%s\n" % CONFIG.reposyncminrate


(fd, reposync_conf_file) = tempfile.mkstemp(text=True)
Expand All @@ -1020,9 +1020,9 @@ def mirrorreposync(url, path, reponame, dist):
handle.close()

ret = run("%s %s --metadata-path %s/reposync --config '%s' --repoid %s --download-path '%s'" % (
cf.cmd['reposync'],
CONFIG.cmd['reposync'],
opts,
cf.cachedir,
CONFIG.cachedir,
reposync_conf_file,
reponame,
path,
Expand All @@ -1045,16 +1045,16 @@ def which(cmd):


def mail(subject, msg):
info(2, 'Sending mail to: %s' % cf.mailto)
info(2, 'Sending mail to: %s' % CONFIG.mailto)
try:
import smtplib
smtp = smtplib.SMTP(cf.smtpserver)
smtp = smtplib.SMTP(CONFIG.smtpserver)
msg = 'Subject: [mrepo] %s\nX-Mailer: mrepo %s\n\n%s' % (subject, VERSION, msg)
for email in cf.mailto.split():
smtp.sendmail(cf.mailfrom, email, 'To: %s\n%s' % (email, msg))
for email in CONFIG.mailto.split():
smtp.sendmail(CONFIG.mailfrom, email, 'To: %s\n%s' % (email, msg))
smtp.quit()
except:
info(1, 'Sending mail via %s failed.' % cf.smtpserver)
info(1, 'Sending mail via %s failed.' % CONFIG.smtpserver)


def readconfig():
Expand Down Expand Up @@ -1162,40 +1162,40 @@ def listrpmlinks(dir):

def main():
### Check availability of commands
for cmd in cf.cmd.keys():
if not cf.cmd[cmd]:
for cmd in CONFIG.cmd.keys():
if not CONFIG.cmd[cmd]:
continue
cmdlist = cf.cmd[cmd].split()
cmdlist = CONFIG.cmd[cmd].split()
if not os.path.isfile(cmdlist[0]):
cmdlist[0] = which(cmdlist[0])
if cmdlist[0] and not os.path.isfile(cmdlist[0]):
error(4, '%s command not found as %s, support disabled' % (cmd, cmdlist[0]))
cf.cmd[cmd] = ''
CONFIG.cmd[cmd] = ''
else:
cf.cmd[cmd] = ' '.join(cmdlist)
if not cf.cmd['createrepo']:
CONFIG.cmd[cmd] = ' '.join(cmdlist)
if not CONFIG.cmd['createrepo']:
error(1, 'No tools found to generate repository metadata. Please install createrepo.')

### Set proxy-related environment variables
if cf.no_proxy:
os.environ['no_proxy'] = cf.no_proxy
if cf.ftp_proxy:
os.environ['ftp_proxy'] = cf.ftp_proxy
if cf.http_proxy:
os.environ['http_proxy'] = cf.http_proxy
if cf.https_proxy:
os.environ['https_proxy'] = cf.https_proxy
if cf.rsync_proxy:
os.environ['RSYNC_PROXY'] = cf.rsync_proxy
if CONFIG.no_proxy:
os.environ['no_proxy'] = CONFIG.no_proxy
if CONFIG.ftp_proxy:
os.environ['ftp_proxy'] = CONFIG.ftp_proxy
if CONFIG.http_proxy:
os.environ['http_proxy'] = CONFIG.http_proxy
if CONFIG.https_proxy:
os.environ['https_proxy'] = CONFIG.https_proxy
if CONFIG.rsync_proxy:
os.environ['RSYNC_PROXY'] = CONFIG.rsync_proxy

### Select list of distributions in order of appearance
if not OPTIONS.dists:
dists = cf.dists
dists = CONFIG.dists
else:
dists = []
for name in OPTIONS.dists:
append = False
for dist in cf.alldists:
for dist in CONFIG.alldists:
if name == dist.nick or name == dist.dist:
dists.append(dist)
append = True
Expand Down Expand Up @@ -1240,7 +1240,7 @@ def main():
len(new),
len(removed),
))
fd = open(cf.logfile, 'a+')
fd = open(CONFIG.logfile, 'a+')
date = time.strftime("%b %d %H:%M:%S", time.gmtime())

def sortedlist(pkgs):
Expand Down Expand Up @@ -1312,7 +1312,7 @@ def formatlist(pkglist):
exitcode = 0

OPTIONS = Options(sys.argv[1:])
cf = readconfig()
CONFIG = readconfig()
try:
main()
except KeyboardInterrupt, e:
Expand Down

0 comments on commit 4c25138

Please sign in to comment.