-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplesync.py
More file actions
executable file
·62 lines (51 loc) · 1.6 KB
/
simplesync.py
File metadata and controls
executable file
·62 lines (51 loc) · 1.6 KB
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
#!/usr/bin/python
from sys import exit
from optparse import OptionParser
from os import walk
import os
usage = "usage: %prog [options] src dst"
parser = OptionParser(usage=usage)
parser.add_option("-f", "--file", dest="filename",
help="write report to FILE", metavar="FILE")
parser.add_option("-r", "--reverse",
action="store_true", dest="reverse", default=False,
help="reverse direction")
(options, args) = parser.parse_args()
if len(args) < 2:
parser.print_usage()
exit(1)
src = args[0]
dst = args[1]
if src.endswith(os.sep):
src = src[:-1]
if dst.endswith(os.sep):
dst = dst[:-1]
if options.reverse:
src, dst = dst, src
entries = walk(src)
dirs_created = set()
files_to_ignore = set(['.DS_Store'])
print 'set -ex'
for dirpath, dirnames, filenames in entries:
dirpath = dirpath[len(src):]
if len(dirpath) == 0:
dirpath = os.sep
#print 'dirpath: %s' % dirpath
#print 'dirnames:'
#for dirname in dirnames:
# print '- %s' % dirname
#print 'filenames:'
for filename in filenames:
if filename in files_to_ignore:
continue
filerelpath = os.path.join(dirpath, filename)
# print filerelpath
srcpath = src + filerelpath
dstpath = dst + filerelpath
dstdirpath = dst + dirpath
if not os.path.exists(dstdirpath) and (dstdirpath not in dirs_created):
print 'mkdir -p "%s"' % dstdirpath
dirs_created.add(dstdirpath)
if not os.path.exists(dstpath):
print 'cp -p "%s" "%s"' % (srcpath, dstpath)
#print '------'