-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsync.py
More file actions
executable file
·91 lines (73 loc) · 2.36 KB
/
sync.py
File metadata and controls
executable file
·91 lines (73 loc) · 2.36 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
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
#!/usr/bin/python
from os import path
import sys
import glob
import subprocess
import shutil
import time
def syncFile(src, dst):
try:
f4sync = glob.glob(src + "*.sh")
f4sync.extend(glob.glob(src + "*.py"))
for f in f4sync:
shutil.copy(f, dst)
return len(f4sync)
except e:
#TODO save error info to log
return -1
programs = ["android_logs",
"android_sqlite",
"fs_timeline",
"jsonizer",
"nodejs_server"
]
git_dir = path.abspath(path.curdir) + path.sep
home_dir = path.expanduser('~') + path.sep
bak_dir = home_dir + "af_code"
dev_dir = home_dir + "Documents/code/lab/forensics/android"
eclipse_workspace = home_dir + "Documents/code/workspace/Forensics"
if not path.isdir(git_dir):
print "Git directory is not found. Terminating..."
sys.exit(-1)
do_sync = False
do_sync_adt = False
do_backup = path.isdir(bak_dir)
if not do_backup:
print "Skipping backup process since backup directory is not found... "
else:
print "Backup directory is set to [%s]" % (bak_dir)
def sync_source_code():
print "Start syncing source code to Git repository... [%s]" % (git_dir)
for program in programs:
src = dev_dir + path.sep + program + path.sep
dst = git_dir + program + path.sep
print "syncing %s ...\t" % program,
rtn = syncFile(src, dst)
if program is 'android_sqlite':
rtn *= syncFile(src + "modules/", dst + "modules/")
if rtn > 0:
print "ok"
else:
print "Failed to sync %s" % program
def sync_adt():
print "Start syncing [%s] project... " % eclipse_workspace,
src = eclipse_workspace + path.sep
rtn = subprocess.call(["cp", "-r", src + "AndroidManifest.xml", src + "res", src + "src", git_dir + "java/"])
if rtn is not 0:
print "Failed to sync [%s] project" % eclipse_workspace
else:
print "ok"
def backup():
print 'Start backing up Git repo...'
archive = shutil.make_archive(bak_dir + "/bak_" + time.strftime("%Y%m%d%H%M"), "gztar", git_dir)
if archive is not None:
print 'Git repo has backed up to [%s]' % archive
print 'Sync has completed'
else:
print 'Failed to back up Git repo.\nQuitting...'
if do_sync_adt:
sync_adt()
if do_backup:
backup()
if do_sync:
sync_source_code()