-
Notifications
You must be signed in to change notification settings - Fork 0
/
pysync.py
executable file
·154 lines (105 loc) · 3.49 KB
/
pysync.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# python
import sys
import os
# modules
import sync
import utils
import repository
from config import config
fake_local = '/Users/bernhardesperester/git/cg/test'
fake_local = 'D:/git/cg/test'
def init():
'''init repository'''
try:
repository.init()
config.save()
except Exception as e:
print e.message
def push(origin = '', *args, **kwargs):
'''push local to remote'''
url = config.getRemote(origin)
if url:
local = utils.getCurrentWorkingDir()
#local = fake_local
local += '/'
print 'push repository to {url}'.format(url = url)
sync_result = sync.push(local, url, *args, **kwargs)
print 'done syncing {files_count} files'.format(files_count = len(sync_result.getFiles()))
def pull(*args, **kwargs):
'''pull remote to local'''
url = config.getRemote('origin')
if url:
local = utils.getCurrentWorkingDir()
#local = fake_local
url += '/'
print 'pull repository from {url}'.format(url = url)
sync_result = sync.pull(local, url, *args, **kwargs)
print 'done syncing {files_count} files'.format(files_count = len(sync_result.getFiles()))
def diff():
'''get diff from local to remote'''
pass
def clone(url = '', *args, **kwargs):
'''clone repository from remte url'''
if url:
dirname, basename = os.path.split(url)
try:
repository_path = os.path.join(utils.getCurrentWorkingDir(), basename)
utils.makeDirs(repository_path)
try:
utils.setCurrentWorkingDir(repository_path)
init()
config.setRemote('origin', url)
config.save()
pull(*args, **kwargs)
except Exception as e:
print e.message
except Exception as e:
print e.message
def setRemote(origin = '', url = '', *args, **kwargs):
'''set remote url'''
print 'set remote {origin} to {url}'.format(origin = origin, url = url)
config.setRemote(origin, url)
config.save()
def removeRemote(origin = '', *args, **kwargs):
'''remove origin'''
pass
def showHelp():
'''show help'''
print '''Help
init Initialize empty repository
clone <url> Clone from remote repository
push <origin> Push to remote repository
pull Pull from remote repository
set-remote <origin> <url> Set remote repository url
remove-remote <origin> Remove repository'''
def prepArgs(*args):
prepped_args = []
prepped_kwargs = {}
for arg in args:
if '=' in arg:
kwarg, kwarg_value = arg.split('=', 2)
if kwarg:
prepped_kwargs[kwarg] = kwarg_value
else:
prepped_args.append(arg)
return prepped_args, prepped_kwargs
def main(args = []):
'''main method'''
if args:
method = args.pop(0)
args, kwargs = prepArgs(*args)
if method == 'init':
return init()
if method == 'clone':
return clone(*args, **kwargs)
if method == 'push':
return push(*args, **kwargs)
if method == 'pull':
return pull(*args, **kwargs)
if method == 'set-remote':
return setRemote(*args, **kwargs)
if method == 'remove-remote':
return removeRemote(*args, **kwargs)
return showHelp()
if __name__ == '__main__':
main(sys.argv[1:])