Skip to content

Commit

Permalink
Merge pull request #22 from stfc/reformat_reflow
Browse files Browse the repository at this point in the history
Reformat continuations and reflow long lines
  • Loading branch information
Oli-Rest authored Jul 18, 2024
2 parents bd6b701 + f9d0271 commit 7872a6a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 29 deletions.
89 changes: 71 additions & 18 deletions mrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,21 @@ def __init__(self, args):
self.create_aggregate_repos = False

try:
opts, args = getopt.getopt(args, 'c:d:fghnqr:t:uvx',
('config=', 'dist=', 'dry-run', 'force', 'generate', 'help', 'quiet', 'repo=',
'type=', 'update', 'verbose', 'version', 'extras'))
opts, args = getopt.getopt(args, 'c:d:fghnqr:t:uvx', (
'config=',
'dist=',
'dry-run',
'force',
'generate',
'help',
'quiet',
'repo=',
'type=',
'update',
'verbose',
'version',
'extras',
))
except getopt.error, instance:
print 'mrepo: %s, try mrepo -h for a list of all the options' % str(instance)
sys.exit(1)
Expand Down Expand Up @@ -350,11 +362,12 @@ def __init__(self, dist, arch, config):
def rewrite(self):
"Rewrite (string) attributes to replace variables by other (string) attributes"
varlist = VARIABLES
varlist.update({'arch': self.arch,
'nick': self.nick,
'dist': self.dist,
'release': self.release,
})
varlist.update({
'arch': self.arch,
'nick': self.nick,
'dist': self.dist,
'release': self.release,
})
for key, value in vars(self).iteritems():
if isinstance(value, types.StringType):
setattr(self, key, substitute(value, varlist))
Expand Down Expand Up @@ -532,8 +545,15 @@ def writesha1(self):
if cursha1 == tmpsha1:
writesha1(sha1file, cursha1)
else:
info(5, '%s: Checksum is different. expect: %s, got: %s' % (self.dist.nick, cursha1, tmpsha1))
info(1, '%s: Directory changed during generating %s repo, please generate again.' % (self.dist.nick, self.name))
info(5, '%s: Checksum is different. expect: %s, got: %s' % (
self.dist.nick,
cursha1,
tmpsha1,
))
info(1, '%s: Directory changed during generating %s repo, please generate again.' % (
self.dist.nick,
self.name,
))

def lock(self, action):
if OPTIONS.dryrun:
Expand All @@ -557,7 +577,10 @@ def lock(self, action):
self.lock(action)
return True
else:
error(0, '%s: Lockfile %s does not exist. Cannot lock. Parallel universe ?' % (self.dist.nick, lockfile))
error(0, '%s: Lockfile %s does not exist. Cannot lock. Parallel universe ?' % (
self.dist.nick,
lockfile,
))
return False

def unlock(self, action):
Expand All @@ -570,9 +593,16 @@ def unlock(self, action):
if pid == '%s' % os.getpid():
os.unlink(lockfile)
else:
error(0, '%s: Existing lock %s found owned by another process with pid %s. This should NOT happen.' % (self.dist.nick, lockfile, pid))
error(0, '%s: Existing lock %s found owned by another process with pid %s. This should NOT happen.' % (
self.dist.nick,
lockfile,
pid,
))
else:
error(0, '%s: Lockfile %s does not exist. Cannot unlock. Something fishy here ?' % (self.dist.nick, lockfile))
error(0, '%s: Lockfile %s does not exist. Cannot unlock. Something fishy here ?' % (
self.dist.nick,
lockfile,
))

def createmd(self):
global EXITCODE
Expand Down Expand Up @@ -985,8 +1015,14 @@ def mirrorreposync(url, path, reponame, dist):
handle.writelines(reposync_conf_contents)
handle.close()

ret = run("%s %s --metadata-path %s/reposync --config '%s' --repoid %s --download-path '%s'" % \
(CONFIG.cmd['reposync'], opts, CONFIG.cachedir, reposync_conf_file, reponame, path))
ret = run("%s %s --metadata-path %s/reposync --config '%s' --repoid %s --download-path '%s'" % (
CONFIG.cmd['reposync'],
opts,
CONFIG.cachedir,
reposync_conf_file,
reponame,
path,
))

# remove the temporary config
os.remove(reposync_conf_file)
Expand Down Expand Up @@ -1189,7 +1225,12 @@ def main():

if new or removed:
msg = msg + '\n\n\tRepo: %s' % repo.name
info(2, '%s: Repository %s changed (new: %d, removed: %d)' % (dist.nick, repo.name, len(new), len(removed)))
info(2, '%s: Repository %s changed (new: %d, removed: %d)' % (
dist.nick,
repo.name,
len(new),
len(removed),
))
file_object = open(CONFIG.logfile, 'a+')
date = time.strftime("%b %d %H:%M:%S", time.gmtime())

Expand All @@ -1206,15 +1247,27 @@ def formatlist(pkglist):
info(4, '%s: New packages: %s' % (dist.nick, formatlist(pkglist)))
distnew += len(pkglist)
for element in pkglist:
file_object.write('%s %s/%s Added %s (%d kiB)\n' % (date, dist.nick, repo.name, element[0], element[1] / 1024))
file_object.write('%s %s/%s Added %s (%d kiB)\n' % (
date,
dist.nick,
repo.name,
element[0],
element[1] / 1024,
))
msg = msg + '\n\t\t+ %s (%d kiB)' % (element[0], element[1] / 1024)

if removed:
pkglist = sortedlist(removed)
info(4, '%s: Removed packages: %s' % (dist.nick, formatlist(pkglist)))
distremoved += len(pkglist)
for element in pkglist:
file_object.write('%s %s/%s Removed %s (%d kiB)\n' % (date, dist.nick, repo.name, element[0], element[1] / 1024))
file_object.write('%s %s/%s Removed %s (%d kiB)\n' % (
date,
dist.nick,
repo.name,
element[0],
element[1] / 1024,
))
msg = msg + '\n\t\t- %s (%d kiB)' % (element[0], element[1] / 1024)

file_object.close()
Expand Down
17 changes: 6 additions & 11 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ class TestSync(unittest.TestCase):
def setUp(self):
pass
def test_synciter1(self):
left = (
1, 2, 4, 5
)
right = (
2, 3, 5, 6, 7
)
left = (1, 2, 4, 5)
right = (2, 3, 5, 6, 7)

onlyright = []
onlyleft = []
Expand All @@ -42,10 +38,10 @@ def test_synciter1(self):
def test_synciter2(self):
left = (
(1, 'l1'), (2, 'l2'), (4, 'l4'), (5, 'l5')
)
)
right = (
(2, 'r2'), (3, 'r3'), (5, 'r5'), (6, 'r6'), (7, 'r7')
)
)

onlyright = []
onlyleft = []
Expand All @@ -61,8 +57,7 @@ def test_synciter2(self):

self.assertEqual(onlyright, [(3, 'r3'), (6, 'r6'), (7, 'r7')])
self.assertEqual(onlyleft, [(1, 'l1'), (4, 'l4')])
self.assertEqual(keyequal, [((2, 'l2'), (2, 'r2')),
((5, 'l5'), (5, 'r5'))])
self.assertEqual(keyequal, [((2, 'l2'), (2, 'r2')), ((5, 'l5'), (5, 'r5'))])


class Testlinksync(unittest.TestCase):
Expand Down Expand Up @@ -108,7 +103,7 @@ class TestConfig:
('1.rpm', path_join(linkbase, '1.rpm')),
('2.rpm', path_join(linkbase, '2.rpm')),
('3.rpm', path_join(linkbase, '3.rpm')),
('a.rpm', path_join(linkbase, 'a', 'a.rpm'))
('a.rpm', path_join(linkbase, 'a', 'a.rpm')),
]
self.links.sort()

Expand Down

0 comments on commit 7872a6a

Please sign in to comment.