-
Notifications
You must be signed in to change notification settings - Fork 0
/
spm-install.py
52 lines (41 loc) · 1.09 KB
/
spm-install.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
#!/usr/bin/env python
try:
import json
loads = json.loads
except ImportError:
import simplejson
loads = simplejson.loads
import os
import urllib
import tarfile
f = open('package.json')
content = f.read()
f.close()
package = loads(content)
dependencies = None
def fetch(key, value):
save = key + '.tgz'
bits = value.split('/')
url = 'http://modules.spmjs.org/%s/%s.tgz' % ('/'.join(bits[:-1]), bits[1])
print 'downloading: %s' % url
urllib.urlretrieve(url, save)
tar = tarfile.open(save)
tar.extractall('sea-modules/' + bits[0])
tar.close()
dist = os.path.join('sea-modules', bits[0], bits[1], 'dist')
version = os.path.join('sea-modules', bits[0], bits[1], bits[2])
try:
os.rmdir(version)
except Exception as e:
pass
try:
os.renames(dist, version)
except Exception as e:
print e
if "dependencies" in package:
dependencies = package["dependencies"]
if dependencies:
for key in dependencies:
value = dependencies[key]
if len(value.split('/')) > 3:
fetch(key, value)