⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lock-check.py

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 PY
字号:
#!/usr/bin/env python### Repository lock checker.  Gets and exclusive lock on the provided### repository, then runs db_stat to see if the lock counts have been### reset to 0.  If not, prints the timestamp of the run and a message### about accumulation.DB_STAT = 'db_stat'import sysimport osimport os.pathimport timeimport fcntlimport getoptdef usage_and_exit(retval):  if retval:    out = sys.stderr  else:    out = sys.stdout  out.write("""Usage: %s [OPTIONS] REPOS-PATHOptions:  --help (-h)    : Show this usage message  --non-blocking : Don't wait for a lock that can't be immediately obtainedObtain an exclusive lock (waiting for one unless --non-blocking ispassed) on REPOS-PATH, then check its lock usage counts.  If there isany accumulation present, report that accumulation to stdout.""" % (os.path.basename(sys.argv[0])))  sys.exit(retval)  def main():  now_time = time.asctime()  repos_path = None  nonblocking = 0  # Parse the options.  optlist, args = getopt.getopt(sys.argv[1:], "h", ['non-blocking', 'help'])  for opt, arg in optlist:    if opt == '--help' or opt == '-h':      usage_and_exit(0)    if opt == '--non-blocking':      nonblocking = 1    else:      usage_and_exit(1)  # We need at least a path to work with, here.  argc = len(args)  if argc < 1 or argc > 1:    usage_and_exit(1)  repos_path = args[0]  fd = open(os.path.join(repos_path, 'locks', 'db.lock'), 'a')  try:    # Get an exclusive lock on the repository lock file, but maybe    # don't wait for it.    try:      mode = fcntl.LOCK_EX      if nonblocking:        mode = mode | fcntl.LOCK_NB      fcntl.lockf(fd, mode)    except IOError:      sys.stderr.write("Error obtaining exclusive lock.\n")      sys.exit(1)    # Grab the db_stat results.    lines = os.popen('%s -ch %s' % (DB_STAT, os.path.join(repos_path, 'db')))    log_lines = []    for line in lines:      pieces = line.split('\t')      if (pieces[1].find('current lock') != -1) and (int(pieces[0]) > 0):        log = ''        if not len(log_lines):          log = log + "[%s] Lock accumulation for '%s'\n" \                % (now_time, repos_path)        log = log + ' ' * 27        log = log + "%s\t%s" % (pieces[0], pieces[1])        log_lines.append(log)    if len(log_lines):      sys.stdout.write(''.join(log_lines))  finally:    # Unlock the lockfile    fcntl.lockf(fd, fcntl.LOCK_UN)  fd.close()if __name__ == "__main__":  main()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -