mirror of
https://github.com/lilydjwg/archrepo2.git
synced 2025-03-10 12:02:43 +00:00
add use-shutil-move option to config file
This commit is contained in:
parent
2aed4df6f8
commit
8297b2aeb2
2 changed files with 27 additions and 4 deletions
|
@ -168,7 +168,7 @@ class EventHandler(pyinotify.ProcessEvent):
|
|||
_n_running = 0
|
||||
|
||||
def my_init(
|
||||
self, filter_pkg, supported_archs, config, wm,
|
||||
self, filter_pkg, supported_archs, config, wm, move_func,
|
||||
):
|
||||
|
||||
notification_type = config.get(
|
||||
|
@ -184,6 +184,7 @@ class EventHandler(pyinotify.ProcessEvent):
|
|||
notification_type.replace('-', '_'),
|
||||
)
|
||||
|
||||
self.move_func = move_func
|
||||
self.filter_pkg = filter_pkg
|
||||
self.moved_away = {}
|
||||
self.created = {}
|
||||
|
@ -332,7 +333,7 @@ class EventHandler(pyinotify.ProcessEvent):
|
|||
newd = os.path.join(base, act.arch)
|
||||
newpath = os.path.join(newd, file)
|
||||
if not same_existent_file(path, newpath):
|
||||
shutil.move(path, newpath)
|
||||
self.move_func(path, newpath)
|
||||
|
||||
act.path = newpath
|
||||
path = newpath
|
||||
|
@ -513,6 +514,13 @@ def repomon(config):
|
|||
# assume none of the archs has regex meta characters
|
||||
regex = re.compile(r'(?:^|/)[^.].*-[^-]+-[\d.]+-(?:' + '|'.join(supported_archs) + r')\.pkg\.tar\.(?:xz|zst)(?:\.sig)?$')
|
||||
|
||||
_use_shutil_move = config.getboolean('use-shutil-move', False)
|
||||
|
||||
if _use_shutil_move:
|
||||
move_func = shutil.move
|
||||
else:
|
||||
move_func = os.rename
|
||||
|
||||
filter_func = partial(filter_pkg, regex)
|
||||
handler = EventHandler(
|
||||
filter_func,
|
||||
|
@ -520,6 +528,7 @@ def repomon(config):
|
|||
supported_archs = supported_archs,
|
||||
config = config,
|
||||
wm = wm,
|
||||
move_func = move_func
|
||||
)
|
||||
ioloop = IOLoop.current()
|
||||
ret = [pyinotify.TornadoAsyncNotifier(
|
||||
|
@ -536,6 +545,7 @@ def repomon(config):
|
|||
path = config.get('spool-directory'),
|
||||
dstpath = os.path.join(config.get('path'), 'any'),
|
||||
wm = wm,
|
||||
move_func = move_func
|
||||
)
|
||||
ret.append(pyinotify.TornadoAsyncNotifier(
|
||||
wm, default_proc_fun=handler,
|
||||
|
@ -545,7 +555,8 @@ def repomon(config):
|
|||
return ret
|
||||
|
||||
class SpoolHandler(pyinotify.ProcessEvent):
|
||||
def my_init(self, filter_pkg, path, dstpath, wm):
|
||||
def my_init(self, filter_pkg, path, dstpath, wm, move_func):
|
||||
self.move_func = move_func
|
||||
self.filter_pkg = filter_pkg
|
||||
self.dstpath = dstpath
|
||||
self._ioloop = IOLoop.current()
|
||||
|
@ -602,4 +613,4 @@ class SpoolHandler(pyinotify.ProcessEvent):
|
|||
|
||||
def dispatch(self, path):
|
||||
filename = os.path.basename(path)
|
||||
shutil.move(path, os.path.join(self.dstpath, filename))
|
||||
self.move_func(path, os.path.join(self.dstpath, filename))
|
||||
|
|
|
@ -57,4 +57,16 @@ notification-secret: JiUHuGY987G76djItfOskOj
|
|||
# If for any reason, you don't want actual database creation or update:
|
||||
#without-db: true
|
||||
|
||||
# Whether to use shutil.move() to move files,
|
||||
# the default is to use os.rename() to move files.
|
||||
#
|
||||
# os. rename()
|
||||
# If src and dst are on same filesystem, rename src to dst.
|
||||
# If src and dst are on different filesystems, the operation will fail.
|
||||
#
|
||||
# shutil.move()
|
||||
# If the destination is on the current filesystem, then os.rename() is used.
|
||||
# Otherwise, src is copied to dst using shutil.copy2() and then removed.
|
||||
use-shutil-move: false
|
||||
|
||||
# vim: se ft=dosini:
|
||||
|
|
Loading…
Add table
Reference in a new issue