Daniel Holbach has proposed merging lp:~dholbach/loco-directory/620394 into 
lp:loco-directory.

Requested reviews:
  loco-directory-dev (loco-directory-dev)
Related bugs:
  #620394 Cleverer 'update' mechanism
  https://bugs.launchpad.net/bugs/620394

-- 
https://code.launchpad.net/~dholbach/loco-directory/620394/+merge/34002
Your team loco-directory-dev is requested to review the proposed merge of 
lp:~dholbach/loco-directory/620394 into lp:loco-directory.
=== modified file '.bzrignore'
--- .bzrignore	2010-07-09 10:54:09 +0000
+++ .bzrignore	2010-08-28 19:29:38 +0000
@@ -9,3 +9,4 @@
 loco_directory/teams/fixtures
 local_settings.py
 loco_directory/ubuntu_website
+data

=== modified file 'loco_directory/common/utils.py'
--- loco_directory/common/utils.py	2010-08-20 13:05:47 +0000
+++ loco_directory/common/utils.py	2010-08-28 19:29:38 +0000
@@ -1,6 +1,24 @@
 import email
 import os
 from copy import deepcopy
+import subprocess
+import datetime
+
+from django.conf import settings
+
+def run_job(which, interval, args=None):
+    stamp_dir = os.path.join(settings.PROJECT_PATH, 'data')
+    if not os.path.exists(stamp_dir):
+        os.makedirs(stamp_dir)
+    stamp_file = os.path.join(stamp_dir, "%s.stamp" % which)
+    if not os.path.exists(stamp_file) or \
+       datetime.datetime.utcfromtimestamp(os.path.getmtime(stamp_file)) + interval < datetime.datetime.now():
+        pwd = os.getcwd()
+        os.chdir(settings.PROJECT_PATH)
+        subprocess.call(["./manage.py", which])
+        os.chdir(pwd)
+        open(stamp_file, "a").close()
+        os.utime(stamp_file, None)
 
 def flat_list(some_list):
     """

=== modified file 'loco_directory/teams/management/commands/update.py'
--- loco_directory/teams/management/commands/update.py	2010-07-09 10:56:56 +0000
+++ loco_directory/teams/management/commands/update.py	2010-08-28 19:29:38 +0000
@@ -2,19 +2,14 @@
 
 from django.core.management.base import NoArgsCommand
 
-import subprocess
-import os
+from common.utils import run_job
 
-from django.conf import settings
+import datetime
 
 class Command(NoArgsCommand):
     help = "Update everything."
 
     def handle_noargs(self, **options):
-        pwd = os.getcwd()
-        os.chdir(settings.PROJECT_PATH)
-        subprocess.call(["./manage.py", "update-countries"])
-        subprocess.call(["./manage.py", "update-languages"])
-        subprocess.call(["./manage.py", "lpupdate"])
-        os.chdir(pwd)
-
+        run_job("update-countries", datetime.timedelta(days=1))
+        run_job("update-languages", datetime.timedelta(days=1))
+        run_job("lpupdate", datetime.timedelta(minutes=20))

_______________________________________________
Mailing list: https://launchpad.net/~loco-directory-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~loco-directory-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to