mirror of
https://github.com/lilydjwg/archrepo2.git
synced 2025-03-10 12:02:43 +00:00
configurable supported archs
This commit is contained in:
parent
5a28db12f2
commit
bcca713e5c
2 changed files with 31 additions and 20 deletions
|
@ -31,9 +31,12 @@ path: /home/lilydjwg/tmpfs/test
|
||||||
# directory. Default is on.
|
# directory. Default is on.
|
||||||
#auto-rename: on
|
#auto-rename: on
|
||||||
|
|
||||||
|
# What archs we support? The default is i686 and x86_64. And you can add more
|
||||||
|
# like arm, armv6h, aarch64. Archs are separated by spaces.
|
||||||
|
#supported-archs: i686 x86_64 arm
|
||||||
|
|
||||||
# By enabling symlink-any, the server will automatically symlink the package
|
# By enabling symlink-any, the server will automatically symlink the package
|
||||||
# files of 'any' architecture to 'arm', 'armv6h', 'armv7h', 'aarch64',
|
# files of 'any' architecture to supported archs.
|
||||||
# 'i686' and 'x86_64'
|
|
||||||
# Default is on.
|
# Default is on.
|
||||||
#symlink-any: on
|
#symlink-any: on
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,6 @@ from . import dbutil
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# handles only arm*, aarch64, x86_64, i686 and any arch packages
|
|
||||||
_supported_archs = ('arm', 'armv6h', 'armv7h', 'aarch64',
|
|
||||||
'i686', 'x86_64', 'any')
|
|
||||||
# assume none of the archs has regex meta characters
|
|
||||||
_pkgfile_pat = re.compile(r'(?:^|/).+-[^-]+-[\d.]+-(?:' + '|'.join(_supported_archs) + r')\.pkg\.tar\.xz(?:\.sig)?$')
|
|
||||||
|
|
||||||
def same_existent_file(a, b):
|
def same_existent_file(a, b):
|
||||||
try:
|
try:
|
||||||
return os.path.samefile(a, b)
|
return os.path.samefile(a, b)
|
||||||
|
@ -40,6 +34,7 @@ def same_existent_file(a, b):
|
||||||
|
|
||||||
class ActionInfo(archpkg.PkgNameInfo):
|
class ActionInfo(archpkg.PkgNameInfo):
|
||||||
def __new__(cls, path, action, four=None, five=None, pkgpath=None):
|
def __new__(cls, path, action, four=None, five=None, pkgpath=None):
|
||||||
|
print(path, action, four)
|
||||||
if four is not None:
|
if four is not None:
|
||||||
return super().__new__(cls, path, action, four, five)
|
return super().__new__(cls, path, action, four, five)
|
||||||
file = os.path.split(pkgpath or path)[1]
|
file = os.path.split(pkgpath or path)[1]
|
||||||
|
@ -224,10 +219,11 @@ class RepoMan:
|
||||||
self._do_remove(toremove)
|
self._do_remove(toremove)
|
||||||
|
|
||||||
class EventHandler(pyinotify.ProcessEvent):
|
class EventHandler(pyinotify.ProcessEvent):
|
||||||
def my_init(self, config, wm, ioloop=None):
|
def my_init(self, filter_pkg, supported_archs, config, wm, ioloop=None):
|
||||||
|
self.filter_pkg = filter_pkg
|
||||||
self.moved_away = {}
|
self.moved_away = {}
|
||||||
self.repomans = {}
|
self.repomans = {}
|
||||||
# TODO: use a expiring dict
|
# TODO: use an expiring dict
|
||||||
self.our_links = set()
|
self.our_links = set()
|
||||||
self._ioloop = ioloop or IOLoop.instance()
|
self._ioloop = ioloop or IOLoop.instance()
|
||||||
|
|
||||||
|
@ -255,7 +251,8 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
(filename text unique,
|
(filename text unique,
|
||||||
pkgrepo text)''')
|
pkgrepo text)''')
|
||||||
|
|
||||||
dirs = [os.path.join(base, x) for x in _supported_archs]
|
self._supported_archs = supported_archs
|
||||||
|
dirs = [os.path.join(base, x) for x in self._supported_archs]
|
||||||
self.files = files = set()
|
self.files = files = set()
|
||||||
for d in dirs:
|
for d in dirs:
|
||||||
os.makedirs(d, exist_ok=True)
|
os.makedirs(d, exist_ok=True)
|
||||||
|
@ -276,10 +273,12 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
oldfiles.update(f[0] for f in self._db.execute('select filename from sigfiles where pkgrepo = ?', (self.name,)))
|
oldfiles.update(f[0] for f in self._db.execute('select filename from sigfiles where pkgrepo = ?', (self.name,)))
|
||||||
oldfiles = {os.path.join(self._db_dir, f) for f in oldfiles}
|
oldfiles = {os.path.join(self._db_dir, f) for f in oldfiles}
|
||||||
|
|
||||||
for f in sorted(filterfalse(filterPkg, files - oldfiles), key=pkgsortkey):
|
for f in sorted(filterfalse(self.filter_pkg, files - oldfiles),
|
||||||
|
key=pkgsortkey):
|
||||||
self.dispatch(f, 'add')
|
self.dispatch(f, 'add')
|
||||||
|
|
||||||
for f in sorted(filterfalse(filterPkg, oldfiles - files), key=pkgsortkey):
|
for f in sorted(filterfalse(self.filter_pkg, oldfiles - files),
|
||||||
|
key=pkgsortkey):
|
||||||
self.dispatch(f, 'remove')
|
self.dispatch(f, 'remove')
|
||||||
|
|
||||||
def process_IN_CLOSE_WRITE(self, event):
|
def process_IN_CLOSE_WRITE(self, event):
|
||||||
|
@ -352,7 +351,7 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
d = newd
|
d = newd
|
||||||
|
|
||||||
if self._symlink_any and act.arch == 'any':
|
if self._symlink_any and act.arch == 'any':
|
||||||
for newarch in _supported_archs:
|
for newarch in self._supported_archs:
|
||||||
if newarch == arch:
|
if newarch == arch:
|
||||||
# this file itself
|
# this file itself
|
||||||
continue
|
continue
|
||||||
|
@ -453,10 +452,10 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
self._db.execute('''delete from sigfiles where filename = ? and pkgrepo = ?''',
|
self._db.execute('''delete from sigfiles where filename = ? and pkgrepo = ?''',
|
||||||
(rpath, self.name))
|
(rpath, self.name))
|
||||||
|
|
||||||
def filterPkg(path):
|
def filter_pkg(regex, path):
|
||||||
if isinstance(path, Event):
|
if isinstance(path, Event):
|
||||||
path = path.pathname
|
path = path.pathname
|
||||||
return not _pkgfile_pat.search(path)
|
return not regex.search(path)
|
||||||
|
|
||||||
def pkgsortkey(path):
|
def pkgsortkey(path):
|
||||||
pkg = archpkg.PkgNameInfo.parseFilename(os.path.split(path)[1])
|
pkg = archpkg.PkgNameInfo.parseFilename(os.path.split(path)[1])
|
||||||
|
@ -466,11 +465,20 @@ def repomon(config):
|
||||||
wm = pyinotify.WatchManager()
|
wm = pyinotify.WatchManager()
|
||||||
ioloop = IOLoop.instance()
|
ioloop = IOLoop.instance()
|
||||||
|
|
||||||
|
supported_archs = config.get('supported-archs', 'i686 x86_64').split()
|
||||||
|
if 'any' not in supported_archs:
|
||||||
|
supported_archs.append('any')
|
||||||
|
# assume none of the archs has regex meta characters
|
||||||
|
regex = re.compile(r'(?:^|/)[^.].*-[^-]+-[\d.]+-(?:' + '|'.join(supported_archs) + r')\.pkg\.tar\.xz(?:\.sig)?$')
|
||||||
|
|
||||||
|
filter_func = partial(filter_pkg, regex)
|
||||||
handler = EventHandler(
|
handler = EventHandler(
|
||||||
filterPkg,
|
filter_func,
|
||||||
config=config,
|
filter_pkg = filter_func,
|
||||||
wm=wm,
|
supported_archs = supported_archs,
|
||||||
ioloop=ioloop,
|
config = config,
|
||||||
|
wm = wm,
|
||||||
|
ioloop = ioloop,
|
||||||
)
|
)
|
||||||
return pyinotify.TornadoAsyncNotifier(
|
return pyinotify.TornadoAsyncNotifier(
|
||||||
wm,
|
wm,
|
||||||
|
|
Loading…
Add table
Reference in a new issue