From a20a673e4cf968abd30476d097bd058729b66088 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 12 Jun 2011 16:14:46 +0200 Subject: [PATCH] added hgbrowse.py for hg repositorybrowser --- .../src/main/resources/sonia/scm/hgbrowse.py | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 plugins/scm-hg-plugin/src/main/resources/sonia/scm/hgbrowse.py diff --git a/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hgbrowse.py b/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hgbrowse.py new file mode 100644 index 0000000000..169da6eee6 --- /dev/null +++ b/plugins/scm-hg-plugin/src/main/resources/sonia/scm/hgbrowse.py @@ -0,0 +1,84 @@ +#!/usr/bin/env ${python} + +pythonPath = os.environ['SCM_PYTHON_PATH'] + +if len(pythonPath) > 0: + pathParts = pythonPath.split(os.pathsep) + for i in range(len(pathParts)): + sys.path.insert(i, pathParts[i]) + + +from mercurial import hg, ui +import datetime, time + +def getName(path): + parts = path.split('/') + length = len(parts) + if path.endswith('/'): + length =- 1 + return parts[length - 1] + +repositoryPath = os.environ['SCM_REPOSITORY_PATH'] + +revision = os.environ['SCM_REVISION'] +path = os.environ['SCM_PATH'] +name = getName(path) +length = 0 +paths = [] +repo = hg.repository(ui.ui(), path = repositoryPath) +mf = repo[revision].manifest() + +if path is "": + length = 1 + for f in mf: + paths.append(f) +else: + length = len(path.split('/')) + 1 + for f in mf: + if f.startswith(path): + paths.append(f) + +files = [] +directories = [] + +for p in paths: + parts = p.split('/') + depth = len(parts) + if depth is length: + file = repo[revision][p] + files.append(file) + elif depth > length: + dirpath = '' + for i in range(0, length): + dirpath += parts[i] + '/' + if not dirpath in directories: + directories.append(dirpath) + +print '' +print '' +print ' ' + revision + '' +# todo print tag, and branch +print ' ' +print ' ' + path + '' +print ' ' + name + '' +print ' true' +print ' ' +for dir in directories: + print ' ' + print ' ' + getName(dir) + '' + print ' ' + dir + '' + print ' true' + print ' ' + +for file in files: + print ' ' + print ' ' + getName(file.path()) + '' + print ' ' + file.path() + '' + print ' false' + print ' ' + str(file.size()) + '' + time = file.date()[0] + print ' ' + str(time).split('.')[0] + '' + print ' ' +print ' ' +print ' ' +print ''