Commit 0b8ed63d50cddc7453e2e3594009c889f5078432

Authored by Marco
1 parent 38507bec

Fix import_emails

src/super_archives/management/commands/import_emails.py
... ... @@ -33,6 +33,8 @@ class Command(BaseCommand, object):
33 33 THREAD_CACHE = {}
34 34 EMAIL_ADDR_CACHE = {}
35 35  
  36 + lock_file = '/var/lock/colab/import_emails.lock'
  37 +
36 38 # A new command line option to get the dump file to parse.
37 39 option_list = BaseCommand.option_list + (
38 40 make_option('--archives_path',
... ... @@ -246,6 +248,7 @@ class Command(BaseCommand, object):
246 248 # This anti-pattern is needed to avoid the transations to
247 249 # get stuck in case of errors.
248 250 transaction.rollback()
  251 + os.remove(self.lock_file)
249 252 raise
250 253  
251 254 count += 1
... ... @@ -257,19 +260,15 @@ class Command(BaseCommand, object):
257 260 def handle(self, *args, **options):
258 261 """Main command method."""
259 262  
260   - lock_file = '/var/lock/colab/import_emails.lock'
261 263  
262 264 # Already running, so quit
263   - if os.path.exists(lock_file):
  265 + if os.path.exists(self.lock_file):
264 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 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 273 archives_path = options.get('archives_path')
275 274 self.log('Using archives_path `%s`' % self.default_archives_path)
... ... @@ -277,9 +276,11 @@ class Command(BaseCommand, object):
277 276 if not os.path.exists(archives_path):
278 277 raise CommandError('archives_path (%s) does not exist' %
279 278 archives_path)
  279 + run_lock = file(self.lock_file, 'w')
  280 + run_lock.close()
280 281  
281 282 self.import_emails(archives_path,
282 283 options.get('all'), options.get('exclude_lists'))
283 284  
284   - os.remove(lock_file)
  285 + os.remove(self.lock_file)
285 286  
... ...