Commit 0b8ed63d50cddc7453e2e3594009c889f5078432
1 parent
38507bec
Exists in
master
and in
39 other branches
Fix import_emails
Showing
1 changed file
with
10 additions
and
9 deletions
Show diff stats
src/super_archives/management/commands/import_emails.py
@@ -33,6 +33,8 @@ class Command(BaseCommand, object): | @@ -33,6 +33,8 @@ class Command(BaseCommand, object): | ||
33 | THREAD_CACHE = {} | 33 | THREAD_CACHE = {} |
34 | EMAIL_ADDR_CACHE = {} | 34 | EMAIL_ADDR_CACHE = {} |
35 | 35 | ||
36 | + lock_file = '/var/lock/colab/import_emails.lock' | ||
37 | + | ||
36 | # A new command line option to get the dump file to parse. | 38 | # A new command line option to get the dump file to parse. |
37 | option_list = BaseCommand.option_list + ( | 39 | option_list = BaseCommand.option_list + ( |
38 | make_option('--archives_path', | 40 | make_option('--archives_path', |
@@ -246,6 +248,7 @@ class Command(BaseCommand, object): | @@ -246,6 +248,7 @@ class Command(BaseCommand, object): | ||
246 | # This anti-pattern is needed to avoid the transations to | 248 | # This anti-pattern is needed to avoid the transations to |
247 | # get stuck in case of errors. | 249 | # get stuck in case of errors. |
248 | transaction.rollback() | 250 | transaction.rollback() |
251 | + os.remove(self.lock_file) | ||
249 | raise | 252 | raise |
250 | 253 | ||
251 | count += 1 | 254 | count += 1 |
@@ -257,19 +260,15 @@ class Command(BaseCommand, object): | @@ -257,19 +260,15 @@ class Command(BaseCommand, object): | ||
257 | def handle(self, *args, **options): | 260 | def handle(self, *args, **options): |
258 | """Main command method.""" | 261 | """Main command method.""" |
259 | 262 | ||
260 | - lock_file = '/var/lock/colab/import_emails.lock' | ||
261 | 263 | ||
262 | # Already running, so quit | 264 | # Already running, so quit |
263 | - if os.path.exists(lock_file): | 265 | + if os.path.exists(self.lock_file): |
264 | self.log(("This script is already running. (If your are sure it's " | 266 | self.log(("This script is already running. (If your are sure it's " |
265 | - "not please delete the lock file in %s')") % lock_file) | 267 | + "not please delete the lock file in %s')") % self.lock_file) |
266 | sys.exit(0) | 268 | sys.exit(0) |
267 | 269 | ||
268 | - if not os.path.exists(os.path.dirname(lock_file)): | ||
269 | - os.mkdir(os.path.dirname(lock_file), 0755) | ||
270 | - | ||
271 | - run_lock = file(lock_file, 'w') | ||
272 | - run_lock.close() | 270 | + if not os.path.exists(os.path.dirname(self.lock_file)): |
271 | + os.mkdir(os.path.dirname(self.lock_file), 0755) | ||
273 | 272 | ||
274 | archives_path = options.get('archives_path') | 273 | archives_path = options.get('archives_path') |
275 | self.log('Using archives_path `%s`' % self.default_archives_path) | 274 | self.log('Using archives_path `%s`' % self.default_archives_path) |
@@ -277,9 +276,11 @@ class Command(BaseCommand, object): | @@ -277,9 +276,11 @@ class Command(BaseCommand, object): | ||
277 | if not os.path.exists(archives_path): | 276 | if not os.path.exists(archives_path): |
278 | raise CommandError('archives_path (%s) does not exist' % | 277 | raise CommandError('archives_path (%s) does not exist' % |
279 | archives_path) | 278 | archives_path) |
279 | + run_lock = file(self.lock_file, 'w') | ||
280 | + run_lock.close() | ||
280 | 281 | ||
281 | self.import_emails(archives_path, | 282 | self.import_emails(archives_path, |
282 | options.get('all'), options.get('exclude_lists')) | 283 | options.get('all'), options.get('exclude_lists')) |
283 | 284 | ||
284 | - os.remove(lock_file) | 285 | + os.remove(self.lock_file) |
285 | 286 |