-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathpythonista-install-boto.py
118 lines (92 loc) · 3.53 KB
/
pythonista-install-boto.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
# Source: https://gist.github.com/najibninaba/5062153
#
# This script installs Boto in Pythonista. Run this script in your root folder and it will download and install Boto along with its
# dependencies. To use Boto, be sure to add boto-module in your sys.path before importing boto like so:
# import sys; sys.path.append('boto-module')
# import boto.ec2
#
# Credits:
# This script is inspired by omz's Evernote Installer script: https://gist.github.com/omz/5048588
#
packages = ['https://pypi.python.org/packages/source/b/boto/boto-2.8.0.tar.gz',
'https://pypi.python.org/packages/source/m/mock/mock-1.0.1.tar.gz',
'https://pypi.python.org/packages/source/r/rsa/rsa-3.1.1.tar.gz',
'https://pypi.python.org/packages/source/t/tox/tox-1.4.zip',
'https://pypi.python.org/packages/source/S/Sphinx/Sphinx-1.1.3.tar.gz',
'https://pypi.python.org/packages/source/s/simplejson/simplejson-2.5.2.tar.gz',
'http://argparse.googlecode.com/files/argparse-1.2.1.tar.gz',
'https://pypi.python.org/packages/source/u/unittest2/unittest2-0.5.1.tar.gz'
]
configparser_src = 'http://hg.python.org/cpython/raw-file/70274d53c1dd/Lib/ConfigParser.py'
import shutil
import urllib
from urlparse import urlparse
import tarfile
import zipfile
import os
def create_module_dir():
try:
os.mkdir('boto-module')
except:
pass
def get_filename_from_url(url):
parsed_url = urlparse(url)
return parsed_url.path.rpartition('/')[-1]
def is_zipfile(f):
return f.endswith('.zip')
def is_targzfile(f):
return f.endswith('.tar.gz')
def download_packages():
for f in packages:
print('Downloading %s' % f)
filepath, headers = urllib.urlretrieve(f)
print('Extracting %s' % filepath)
filename = get_filename_from_url(f)
if is_targzfile(filename):
t = tarfile.open(filepath, 'r')
t.extractall()
t.close()
elif is_zipfile(filename):
z = zipfile.ZipFile(filepath, 'r')
z.extractall()
z.close()
def install_configparser_src():
print('Installing ConfigParser...')
filepath, headers = urllib.urlretrieve(configparser_src)
shutil.move(filepath, 'boto-module/ConfigParser.py')
def install_packages():
print('Installing boto...')
shutil.move('boto-2.8.0/boto', 'boto-module/boto')
shutil.rmtree('boto-2.8.0')
print('Installing mock...')
shutil.move('mock-1.0.1/mock.py', 'boto-module/mock.py')
shutil.rmtree('mock-1.0.1')
print('Installing rsa...')
shutil.move('rsa-3.1.1/rsa', 'boto-module/rsa')
shutil.rmtree('rsa-3.1.1')
print('Installing tox...')
shutil.move('tox-1.4/tox', 'boto-module/tox')
shutil.rmtree('tox-1.4')
print('Installing Sphinx...')
shutil.move('Sphinx-1.1.3/sphinx', 'boto-module/sphinx')
shutil.rmtree('Sphinx-1.1.3')
print('Installing simplejson...')
shutil.move('simplejson-2.5.2/simplejson', 'boto-module/simplejson')
shutil.rmtree('simplejson-2.5.2')
print('Installing argparse...')
shutil.move('argparse-1.2.1/argparse.py', 'boto-module/argparse.py')
shutil.rmtree('argparse-1.2.1')
print('Installing unittest2...')
shutil.move('unittest2-0.5.1/unittest2', 'boto-module/unittest2')
shutil.rmtree('unittest2-0.5.1')
def reload_pythonista_editor():
print('Reloading Pythonista editor')
import editor
editor.reload_files()
if __name__ == '__main__':
create_module_dir()
download_packages()
install_packages()
install_configparser_src()
reload_pythonista_editor()
print('All done!')