MCPcopy Create free account
hub / github.com/ActiveState/code / main

Function main

recipes/Python/576729_Simple_Version_Control/recipe-576729.py:128–168  ·  view source on GitHub ↗
(argv)

Source from the content-addressed store, hash-verified

126 sys.exit(code)
127
128def main(argv):
129 # XXX add support for branching
130 # XXX support .N for output
131 if len(argv) <= 1:
132 talkback(help_msg, code=0)
133 if len(argv) < 3:
134 talkback('Not enough arguments. Need a command and filename.', help=True)
135 command = argv[1].lower()
136 if command not in 'log extract diff add update l e d a u'.split():
137 talkback('Unknown command: ' + command, help=True)
138 command = command[:1]
139 filename = argv[2]
140 repo_fn = get_repo_fn(filename)
141
142 if command in 'le':
143 if not os.path.exists(repo_fn):
144 talkback(repo_fn + ' not found')
145 v = int(argv[3]) if len(argv) >= 4 else None
146 if command == 'l':
147 print_log(repo_fn, v)
148 else:
149 print get_version(repo_fn, v),
150 elif command == 'd':
151 v1 = int(argv[3]) if len(argv) >= 4 else None
152 v2 = int(argv[4]) if len(argv) >= 5 else filename
153 print diff(repo_fn, v1, v2, context=True),
154 elif command in 'au':
155 if not os.path.exists(filename):
156 talkback('Cannot find file: ' + filename)
157 d = diff(repo_fn, None, filename)
158 if len(d.splitlines()) == 1:
159 talkback('File is already current. There are no changes.', code=0)
160 msg = ' '.join(argv[3:])
161 create = not os.path.exists(repo_fn)
162 repo_file = open(repo_fn, 'a+')
163 print >> repo_file, make_header(filename, msg, create)
164 print >> repo_file, d,
165 repo_file.close()
166 talkback('Added to ' + repo_fn, code=0)
167 else:
168 talkback('Unreachable')
169
170
171if __name__ == '__main__':

Callers 1

recipe-576729.pyFile · 0.70

Calls 12

talkbackFunction · 0.85
get_repo_fnFunction · 0.85
print_logFunction · 0.85
diffFunction · 0.85
make_headerFunction · 0.85
get_versionFunction · 0.70
openFunction · 0.50
lowerMethod · 0.45
splitMethod · 0.45
existsMethod · 0.45
joinMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected