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
|
_n_running = 0
|
||||||
|
|
||||||
def my_init(
|
def my_init(
|
||||||
self, filter_pkg, supported_archs, config, wm,
|
self, filter_pkg, supported_archs, config, wm, move_func,
|
||||||
):
|
):
|
||||||
|
|
||||||
notification_type = config.get(
|
notification_type = config.get(
|
||||||
|
@ -184,6 +184,7 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
notification_type.replace('-', '_'),
|
notification_type.replace('-', '_'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.move_func = move_func
|
||||||
self.filter_pkg = filter_pkg
|
self.filter_pkg = filter_pkg
|
||||||
self.moved_away = {}
|
self.moved_away = {}
|
||||||
self.created = {}
|
self.created = {}
|
||||||
|
@ -332,7 +333,7 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
newd = os.path.join(base, act.arch)
|
newd = os.path.join(base, act.arch)
|
||||||
newpath = os.path.join(newd, file)
|
newpath = os.path.join(newd, file)
|
||||||
if not same_existent_file(path, newpath):
|
if not same_existent_file(path, newpath):
|
||||||
shutil.move(path, newpath)
|
self.move_func(path, newpath)
|
||||||
|
|
||||||
act.path = newpath
|
act.path = newpath
|
||||||
path = newpath
|
path = newpath
|
||||||
|
@ -513,6 +514,13 @@ def repomon(config):
|
||||||
# assume none of the archs has regex meta characters
|
# assume none of the archs has regex meta characters
|
||||||
regex = re.compile(r'(?:^|/)[^.].*-[^-]+-[\d.]+-(?:' + '|'.join(supported_archs) + r')\.pkg\.tar\.(?:xz|zst)(?:\.sig)?$')
|
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)
|
filter_func = partial(filter_pkg, regex)
|
||||||
handler = EventHandler(
|
handler = EventHandler(
|
||||||
filter_func,
|
filter_func,
|
||||||
|
@ -520,6 +528,7 @@ def repomon(config):
|
||||||
supported_archs = supported_archs,
|
supported_archs = supported_archs,
|
||||||
config = config,
|
config = config,
|
||||||
wm = wm,
|
wm = wm,
|
||||||
|
move_func = move_func
|
||||||
)
|
)
|
||||||
ioloop = IOLoop.current()
|
ioloop = IOLoop.current()
|
||||||
ret = [pyinotify.TornadoAsyncNotifier(
|
ret = [pyinotify.TornadoAsyncNotifier(
|
||||||
|
@ -536,6 +545,7 @@ def repomon(config):
|
||||||
path = config.get('spool-directory'),
|
path = config.get('spool-directory'),
|
||||||
dstpath = os.path.join(config.get('path'), 'any'),
|
dstpath = os.path.join(config.get('path'), 'any'),
|
||||||
wm = wm,
|
wm = wm,
|
||||||
|
move_func = move_func
|
||||||
)
|
)
|
||||||
ret.append(pyinotify.TornadoAsyncNotifier(
|
ret.append(pyinotify.TornadoAsyncNotifier(
|
||||||
wm, default_proc_fun=handler,
|
wm, default_proc_fun=handler,
|
||||||
|
@ -545,7 +555,8 @@ def repomon(config):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
class SpoolHandler(pyinotify.ProcessEvent):
|
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.filter_pkg = filter_pkg
|
||||||
self.dstpath = dstpath
|
self.dstpath = dstpath
|
||||||
self._ioloop = IOLoop.current()
|
self._ioloop = IOLoop.current()
|
||||||
|
@ -602,4 +613,4 @@ class SpoolHandler(pyinotify.ProcessEvent):
|
||||||
|
|
||||||
def dispatch(self, path):
|
def dispatch(self, path):
|
||||||
filename = os.path.basename(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:
|
# If for any reason, you don't want actual database creation or update:
|
||||||
#without-db: true
|
#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:
|
# vim: se ft=dosini:
|
||||||
|
|
Loading…
Add table
Reference in a new issue