summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2011-12-15 22:44:30 (GMT)
committerJohn (J5) Palmieri <johnp@redhat.com>2011-12-15 22:44:30 (GMT)
commit70b60942a887e7ab10e362344a423b51d2f99adc (patch)
tree427021b03d88afa7b06f87f46981589610c53cef
parentdb9a3c733dee7b3cdabab6257b8f65bd4ec7a131 (diff)
downloadfedoracommunity-70b60942a887e7ab10e362344a423b51d2f99adc.zip
fedoracommunity-70b60942a887e7ab10e362344a423b51d2f99adc.tar.gz
fedoracommunity-70b60942a887e7ab10e362344a423b51d2f99adc.tar.xz
split version mapper into a module and executable for running in cron
* fcomm-index-latest-builds will produce a lock file when running so it is safe to run as a cron job
-rw-r--r--MANIFEST.in1
-rwxr-xr-xbin/fcomm-index-latest-builds45
-rw-r--r--fedoracommunity/search/latest_version_mapper.py34
3 files changed, 63 insertions, 17 deletions
diff --git a/MANIFEST.in b/MANIFEST.in
index 86e4641..b688c81 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -12,3 +12,4 @@ include AUTHORS
include COPYING
include build.ini
include bin/fcomm-index-packages
+include bin/fcomm-index-latest-builds
diff --git a/bin/fcomm-index-latest-builds b/bin/fcomm-index-latest-builds
new file mode 100755
index 0000000..74db204
--- /dev/null
+++ b/bin/fcomm-index-latest-builds
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+# use this script when running the indexer from cron
+
+import sys
+import os
+import shutil
+
+from fedoracommunity.search.latest_version_mapper import run
+from lockfile import LockFile
+from optparse import OptionParser
+
+if __name__=="__main__":
+ parser = OptionParser()
+ parser.add_option("-p", "--path", dest="cache_path",
+ help="path to where we create or update the version map",
+ metavar="CACHEPATH")
+
+ (options, args) = parser.parse_args()
+ lockfile = LockFile(os.path.join(options.cache_path, '.fcomm_version_mapper_lock'))
+
+ try:
+ lockfile.acquire(timeout=30)
+ except Exception as e:
+ print "Error acquiring lock file: %s" % str(e)
+ exit(-1)
+
+ try:
+ run(cache_path=options.cache_path)
+ if options.icons_dest is not None:
+ icon_dir = os.path.join(options.cache_path, 'icons')
+
+ for file_name in os.listdir(icon_dir):
+ file_path = os.path.join(icon_dir, file_name)
+ if os.path.isdir(file_path) and not os.path.islink(file_path):
+ shutil.move(file_path, options.icon_dest)
+ if options.index_db_dest is not None:
+ index_dir = os.path.join(options.cache_path, 'search')
+
+ for file_name in os.listdir(index_dir):
+ file_path = os.path.join(index_dir, file_name)
+ if os.path.isdir(file_path) and not os.path.islink(file_path):
+ shutil.move(file_path, options.index_db_dest)
+ finally:
+ lockfile.release()
diff --git a/fedoracommunity/search/latest_version_mapper.py b/fedoracommunity/search/latest_version_mapper.py
index 65a5b00..61bebbc 100644
--- a/fedoracommunity/search/latest_version_mapper.py
+++ b/fedoracommunity/search/latest_version_mapper.py
@@ -1,4 +1,5 @@
import sys
+import os
import xappy
import koji
@@ -95,7 +96,7 @@ class Mapper(object):
self.iconn.add(processed_doc)
self.iconn.flush()
- def init_db(self):
+ def init_db(self, *args):
"""
loop through all packages and get the latest builds for koji tags
listed in distmappings
@@ -319,25 +320,24 @@ class Mapper(object):
self.iconn.close()
self.sconn.close()
-def usage():
- print "Usage: %s init | update" % sys.argv[0]
- exit(-1)
+def run(cache_path, action=None, timestamp=None):
-def main(argv):
- action = None
- argc = len(argv)
- if argc < 2:
- usage()
- if argv[1] == 'init':
+ versionmap_path = os.path.join(cache_path, 'versionmap')
+ if action is None:
+ if os.path.isdir(versionmap_path):
+ # we assume we need to update because the path exists
+ action = Mapper.update_db
+ else:
+ # otherwise we assume we need to create the db
+ action = Mapper.init_db
+ elif action == 'init':
action = Mapper.init_db
- elif argv[1] == 'update':
+ elif action == 'update':
action = Mapper.update_db
else:
- usage()
+ print "Unknown action %s" % action
+ exit(-1)
- mapper = Mapper('versionmap')
- action(mapper, *argv[2:])
+ mapper = Mapper(versionmap_path)
+ action(mapper, timestamp)
mapper.cleanup()
-
-if __name__ == '__main__':
- main(sys.argv)