This repository has been archived by the owner on Feb 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
executable file
·80 lines (61 loc) · 2.12 KB
/
code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
import os
import sys
import subprocess
import importlib
from utilities import isGit, isMercurial, isBazaar
class CodeRepository:
def __init__(self):
'''
Initialize the code repository class.
'''
self.executingDirectory = os.path.dirname(os.path.realpath(__file__))
self.extensionDirectory = os.path.join(self.executingDirectory, "extensions")
def run(self, args):
'''
Run the given command and arguments against the current working directory.
'''
executed = self.executeExtension(args[0], args[1:])
# If no extension was found then we execute the command as if
# it was naturally called.
if not executed:
commandWithArgs = args[:]
commandWithArgs.insert(0, "vcs")
if isGit():
commandWithArgs[0] = "git"
subprocess.call(commandWithArgs)
executed = True
if isMercurial():
commandWithArgs[0] = "hg"
subprocess.call(commandWithArgs)
executed = True
if isBazaar():
commandWithArgs[0] = "bzr"
subprocess.call(commandWithArgs)
executed = True
if not executed:
print("No repository found")
exit(3)
def executeExtension(self, extension, arguments):
'''
Find the named extension and attempt to execute it with the given arguments.
'''
extensionPath = "extensions.{0}".format(extension)
extensionExecuted = False
try:
module = importlib.import_module(extensionPath)
method = getattr(module, extension)
method(arguments)
extensionExecuted = True
except ImportError:
pass
finally:
pass
return extensionExecuted
if __name__ == "__main__": #pragma: no cover
args = sys.argv
if len(args) < 2:
print("Please supply a command.")
exit(3)
repo = CodeRepository()
repo.run(args[1:])