@@ -23,24 +23,27 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import platform
VERSION = (1, 2, 0, 'beta')
__version__ = '.'.join((str(each) for each in VERSION[:4]))
__dbversion__ = 3 #defines current db version for migrations
__platform__ = platform.system()
PLATFORM_WIN = ('Windows',)
PLATFORM_OTHERS = ('Linux', 'Darwin', 'FreeBSD',)
try:
from rhodecode.lib.utils import get_current_revision
_rev = get_current_revision()
except ImportError:
#this is needed when doing some setup.py operations
_rev = False
if len(VERSION) > 3 and _rev:
__version__ += ' [rev:%s]' % _rev[0]
def get_version():
"""Returns shorter version (digit parts only) as string."""
import os, time
import sys
from warnings import warn
from multiprocessing.util import Finalize
import errno
from rhodecode import __platform__, PLATFORM_WIN
if __platform__ in PLATFORM_WIN:
import ctypes
def kill(pid):
"""kill function for Win32"""
kernel32 = ctypes.windll.kernel32
handle = kernel32.OpenProcess(1, 0, pid)
return (0 != kernel32.TerminateProcess(handle, 0))
else:
kill = os.kill
class LockHeld(Exception):pass
class DaemonLock(object):
"""daemon locking
USAGE:
l = DaemonLock(desc='test lock')
main()
l.release()
except LockHeld:
sys.exit(1)
@@ -49,57 +62,57 @@ class DaemonLock(object):
self.trylock()
self.makelock(lockname, self.pidfile)
return True
def trylock(self):
running_pid = False
if self.debug:
print 'checking for already running process'
pidfile = open(self.pidfile, "r")
pidfile.seek(0)
running_pid = int(pidfile.readline())
pidfile.close()
print 'lock file present running_pid: %s, checking for execution'\
% running_pid
# Now we check the PID from lock file matches to the current
# process PID
if running_pid:
os.kill(running_pid, 0)
kill(running_pid, 0)
except OSError, exc:
if exc.errno in (errno.ESRCH, errno.EPERM):
print "Lock File is there but the program is not running"
print "Removing lock file for the: %s" % running_pid
self.release()
raise
print "You already have an instance of the program running"
print "It is running as process %s" % running_pid
raise LockHeld()
except IOError, e:
if e.errno != 2:
def release(self):
"""releases the pid by removing the pidfile
"""
print 'trying to release the pidlock'
if self.callbackfn:
#execute callback function on release
print 'executing callback function %s' % self.callbackfn
self.callbackfn()
print 'removing pidfile %s' % self.pidfile
os.remove(self.pidfile)
self.held = False
except OSError, e:
Status change: