forked from maxwit/withost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsm
executable file
·105 lines (84 loc) · 2.37 KB
/
msm
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
#!/usr/bin/python
import os, sys
import platform
import string
import shutil
from optparse import OptionParser
from dist import distrib
from tree import dir_tree
version = '5.2'
def xcopy(dir_src, dir_dst, ext):
if not os.path.exists(dir_src):
print '"%s" does not exist!'
return
src_list = os.listdir(dir_src)
try:
dst_list = os.listdir(dir_dst)
except:
dst_list = []
for fn in src_list:
src = '/'.join([dir_src, fn])
dst = '/'.join([dir_dst, fn])
if os.path.isdir(src):
xcopy(src, dst, ext)
elif fn.endswith(ext) and fn not in dst_list:
parent = os.path.dirname(dst)
if not os.path.exists(parent):
os.makedirs(parent)
print '%s -> %s' % (src, dst)
shutil.copyfile(src, dst)
def cache_sync(distro, release, arch):
if distro == 'ubuntu':
dir_src = '/var/cache/apt/archives'
ext = '.deb'
elif distro in ['redhat', 'centos', 'fedora']:
dir_src = '/var/cache/yum/%s/%s' % (arch, release.split('.')[0])
ext = '.rpm'
else:
print distro + ' not supported!'
exit(1)
dir_dst = opt.path
#/packages[/distro/release/arch/]
dir_dst = '/'.join([dir_dst, distro, release, arch])
xcopy(dir_src, dir_dst, ext)
xcopy(dir_dst, dir_src, ext)
if __name__ == '__main__':
if os.getuid() != 0:
print 'pls run as root or with sudo!'
exit()
#opt_parser = OptionParser()
#opt_parser.add_option('-s', '--sync', dest='path',
# help='path to sync repo cache with')
#opt_parser.add_option('-i', '--install', dest='install',
# help='install package')
#opt_parser.add_option('-v', '--version', dest='version',
# default=False, action='store_true',
# help='show WitHost version')
#(opt, args) = opt_parser.parse_args()
#if opt.version:
# print 'WitHost v%s\nby MaxWit Software (http://www.maxwit.com)\n' % version
# exit()
#if opt.path:
# (distro, release) = platform.dist()[0:2]
# arch = platform.processor()
# cache_sync(distro.lower(), release, arch)
# exit()
try:
dist = distrib.get_distro()
except Exception, e:
print e
opt_parser.print_help()
exit()
#print "System setup: %s %s\n" % (dist.name, dist.version)
#dist.sys_init()
if len(sys.argv) < 2:
print 'usage: %s install/remove/list packages' % sys.argv[0]
exit(1)
print
if sys.argv[1] == 'install':
dist.setup(sys.argv[2:])
elif sys.argv[1] == 'list':
app_list = dist.get_app_list()
for key in app_list:
print '%s - %s' % (key, app_list[key])
print