1 # Copyright (c) 2011 Intel, Inc.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the Free
5 # Software Foundation; either version 2 of the License, or any later version.
10 class LockfileError(Exception):
11 """ Lockfile Exception"""
14 class SimpleLockfile(object):
15 """ Simple implementation of lockfile """
16 def __init__(self, fpath):
21 """ acquire the lock """
23 self.lockf = os.open(self.fpath,
24 os.O_CREAT | os.O_EXCL | os.O_WRONLY)
25 except OSError as err:
26 if err.errno == errno.EEXIST:
27 raise LockfileError("File %s is locked already" % self.fpath)
34 """ release the lock """
37 except OSError as err:
38 if err.errno == errno.ENOENT:
45 def __exit__(self, *args):