Skip to content

Commit

Permalink
Give Dist and Repo _call_hook functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jrha committed Jul 19, 2024
1 parent 5e3ff5a commit 20e2b4e
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions mrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ def __init__(self, dist, arch, config):
self.sslkey = None
self.sslca = None

def _call_hook(self, hook_name):
if hook_name in CONFIG.hooks and CONFIG.hooks[hook_name]:
run(' '.join([
CONFIG.hooks[hook_name],
hook_name,
self.name,
self.srcdir,
self.dir,
]))

def rewrite(self):
"Rewrite (string) attributes to replace variables by other (string) attributes"
Expand Down Expand Up @@ -478,19 +487,22 @@ def __init__(self, name, url, dist, config):
def __repr__(self):
return self.name

def mirror(self):
"Check URL and pass on to mirror-functions."
global EXITCODE

if CONFIG.hooks['pre-update']:
def _call_hook(self, hook_name):
if hook_name in CONFIG.hooks and CONFIG.hooks[hook_name]:
run(' '.join([
CONFIG.hooks['pre-update'],
'pre-update',
CONFIG.hooks[hook_name],
hook_name,
self.name,
self.url,
self.srcdir,
]))

def mirror(self):
"Check URL and pass on to mirror-functions."
global EXITCODE

_call_hook('pre-update')

### Make a snapshot of the directory
self.oldlist = self.rpmlist()
self.newlist = self.oldlist
Expand Down Expand Up @@ -520,14 +532,7 @@ def mirror(self):
### Make a snapshot of the directory
self.newlist = self.rpmlist()

if CONFIG.hooks['post-update']:
run(' '.join([
CONFIG.hooks['post-update'],
'post-update',
self.name,
self.url,
self.srcdir,
]))
_call_hook('post-update')

def rpmlist(self):
"Capture a list of packages in the repository"
Expand Down Expand Up @@ -587,8 +592,7 @@ def lock(self, action):
if OPTIONS.dryrun:
return True

if CONFIG.hooks['lock']:
run('%s %s' % (CONFIG.hooks['lock'], self.srcdir))
_call_hook('lock')

lockfile = path_join(CONFIG.lockdir, self.dist.nick, action + '-' + self.name + '.lock')
mkdir(os.path.dirname(lockfile))
Expand Down Expand Up @@ -620,8 +624,7 @@ def unlock(self, action):
if OPTIONS.dryrun:
return

if CONFIG.hooks['unlock']:
run('%s %s' % (CONFIG.hooks['unlock'], self.srcdir))
_call_hook('unlock')

lockfile = path_join(CONFIG.lockdir, self.dist.nick, action + '-' + self.name + '.lock')
info(6, '%s: Removing lock %s' % (self.dist.nick, lockfile))
Expand Down

0 comments on commit 20e2b4e

Please sign in to comment.