Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/planemo/git.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
| author | bcclaywell |
|---|---|
| date | Mon, 12 Oct 2015 17:43:33 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d67268158946 |
|---|---|
| 1 """ Utilities for interacting with git using planemo abstractions. | |
| 2 """ | |
| 3 import subprocess | |
| 4 from planemo import io | |
| 5 | |
| 6 | |
| 7 def command_clone(ctx, src, dest, bare=False): | |
| 8 """ Take in ctx to allow more configurability down the road. | |
| 9 """ | |
| 10 bare_arg = "" | |
| 11 if bare: | |
| 12 bare_arg = "--bare" | |
| 13 return "git clone %s '%s' '%s'" % (bare_arg, src, dest) | |
| 14 | |
| 15 | |
| 16 def clone(*args, **kwds): | |
| 17 command = command_clone(*args, **kwds) | |
| 18 return io.shell(command) | |
| 19 | |
| 20 | |
| 21 def rev(ctx, directory): | |
| 22 """ Raw revision for git directory specified. | |
| 23 | |
| 24 Throws ``RuntimeError`` if not a git directory. | |
| 25 """ | |
| 26 cmd_template = "cd '%s' && git rev-parse HEAD" | |
| 27 cmd = cmd_template % directory | |
| 28 stdout, _ = io.communicate( | |
| 29 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE | |
| 30 ) | |
| 31 return stdout.strip() | |
| 32 | |
| 33 | |
| 34 def is_rev_dirty(ctx, directory): | |
| 35 cmd = "cd '%s' && git diff --quiet" % directory | |
| 36 return io.shell(cmd) != 0 | |
| 37 | |
| 38 | |
| 39 def rev_if_git(ctx, directory): | |
| 40 try: | |
| 41 the_rev = rev(ctx, directory) | |
| 42 is_dirtry = is_rev_dirty(ctx, directory) | |
| 43 if is_dirtry: | |
| 44 the_rev += "-dirty" | |
| 45 return the_rev | |
| 46 except RuntimeError: | |
| 47 return None |
