aboutsummaryrefslogtreecommitdiffstats
path: root/git_deps/handler.py
diff options
context:
space:
mode:
authorAdam Spiers <github@adamspiers.org>2018-05-16 16:54:33 +0100
committerGitHub <noreply@github.com>2018-05-16 16:54:33 +0100
commitc091a477d14ae74bb7f1e08d7c5bc5c3bcfd7d20 (patch)
tree01abbbeea250e834c35bed73ac84934c52705ae8 /git_deps/handler.py
parent9a741f07167dcb6cc81a8f87036d1ea75c4270d3 (diff)
parent02e79d29f71feb795779d97825644ad4172598ad (diff)
downloadgit-deps-c091a477d14ae74bb7f1e08d7c5bc5c3bcfd7d20.tar.gz
Merge pull request #71 from aspiers/module
package as a Python module
Diffstat (limited to 'git_deps/handler.py')
-rwxr-xr-xgit_deps/handler.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/git_deps/handler.py b/git_deps/handler.py
new file mode 100755
index 0000000..572ed84
--- /dev/null
+++ b/git_deps/handler.py
@@ -0,0 +1,65 @@
+#!/usr/bin/python
+
+from __future__ import print_function
+
+import logging
+import logging.handlers
+import os
+import re
+import subprocess
+import sys
+import urllib
+from urlparse import urlparse
+
+from git_deps.utils import abort
+
+
+def usage():
+ abort("usage: git-handler URL")
+
+
+def get_logger():
+ logger = logging.getLogger('foo')
+ # logger.setLevel(logging.DEBUG)
+
+ slh = logging.handlers.SysLogHandler(address='/dev/log')
+ slf = logging.Formatter('gitfile-handler: %(message)s')
+ slh.setFormatter(slf)
+ logger.addHandler(slh)
+ logger.addHandler(logging.StreamHandler())
+
+ return logger
+
+
+def main(args):
+ if len(args) != 1:
+ usage()
+
+ logger = get_logger()
+
+ url = args[0]
+ logger.debug("received URL: %s" % url)
+ if re.search(r'%23', url):
+ # Uh-oh, double-encoded URIs! Some versions of Chrome
+ # encode the value you set location.href too.
+ url = urllib.unquote(url)
+ logger.debug("unquoted: %s" % url)
+ url = urlparse(url)
+ logger.debug("parsed: %r" % repr(url))
+
+ if url.scheme != 'gitfile':
+ abort("URL must use gitfile:// scheme")
+
+ repo = os.path.join(url.netloc, url.path)
+ rev = url.fragment
+ os.chdir(repo)
+
+ subprocess.Popen(['gitk', '--all', '--select-commit=%s' % rev])
+
+
+def run():
+ main(sys.argv[1:])
+
+
+if __name__ == "__main__":
+ run()