summaryrefslogtreecommitdiff
path: root/devel/management/commands/reporead_inotify.py
diff options
context:
space:
mode:
Diffstat (limited to 'devel/management/commands/reporead_inotify.py')
-rw-r--r--[-rwxr-xr-x]devel/management/commands/reporead_inotify.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/devel/management/commands/reporead_inotify.py b/devel/management/commands/reporead_inotify.py
index c74762eb..8c1e47bf 100755..100644
--- a/devel/management/commands/reporead_inotify.py
+++ b/devel/management/commands/reporead_inotify.py
@@ -23,7 +23,7 @@ import threading
import time
from django.core.management.base import BaseCommand, CommandError
-from django.db import connection
+from django.db import connection, transaction
from main.models import Arch, Repo
from .reporead import read_repo
@@ -53,6 +53,11 @@ class Command(BaseCommand):
self.path_template = path_template
notifier = self.setup_notifier()
+ # this thread is done using the database; all future access is done in
+ # the spawned read_repo() processes, so close the otherwise completely
+ # idle connection.
+ connection.close()
+
logger.info('Entering notifier loop')
notifier.loop()
@@ -61,15 +66,18 @@ class Command(BaseCommand):
if hasattr(thread, 'cancel'):
thread.cancel()
+ @transaction.commit_on_success
def setup_notifier(self):
'''Set up and configure the inotify machinery and logic.
This takes the provided or default path_template and builds a list of
directories we need to watch for database updates. It then validates
and passes these on to the various pyinotify pieces as necessary and
finally builds and returns a notifier object.'''
+ transaction.commit_manually()
arches = Arch.objects.filter(agnostic=False)
repos = Repo.objects.all()
- arch_path_map = dict((arch, None) for arch in arches)
+ transaction.set_dirty()
+ arch_path_map = {arch: None for arch in arches}
all_paths = set()
total_paths = 0
for arch in arches:
@@ -77,7 +85,7 @@ class Command(BaseCommand):
for repo in repos)
# take a python format string and generate all unique combinations
# of directories from it; using set() ensures we filter it down
- paths = set(self.path_template % values for values in combos)
+ paths = {self.path_template % values for values in combos}
total_paths += len(paths)
all_paths |= paths
arch_path_map[arch] = paths
@@ -91,11 +99,6 @@ class Command(BaseCommand):
raise CommandError('path template did not uniquely '
'determine architecture for each file')
- # this thread is done using the database; all future access is done in
- # the spawned read_repo() processes, so close the otherwise completely
- # idle connection.
- connection.close()
-
# A proper atomic replacement of the database as done by rsync is type
# IN_MOVED_TO. repo-add/remove will finish with a IN_CLOSE_WRITE.
mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVED_TO