Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat continuations and reflow long lines #22

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -346,11 +358,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 @@ -529,8 +542,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 @@ -554,7 +574,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 @@ -567,9 +590,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 @@ -983,8 +1013,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 @@ -1187,7 +1223,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 @@ -1204,15 +1245,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
Loading