-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·162 lines (147 loc) · 5.89 KB
/
install
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
from __future__ import division, with_statement, print_function
from contextlib import closing
import json
import os
import sys
import tarfile
from urllib.request import urlopen
from threading import Thread
import subprocess
def makefolder(path):
dirname = os.path.dirname(path)
if not os.path.exists(dirname):
os.makedirs(dirname)
class Install(Thread):
base_url = 'http://downloads.openmedialibrary.com/'
status = {}
def __init__(self, target):
self.target = target
Thread.__init__(self)
self.daemon = True
self.start()
def run(self):
target = self.target
target = os.path.normpath(os.path.join(os.path.abspath(target)))
if not os.path.exists(target):
os.makedirs(target)
os.chdir(target)
release = self.get_release()
self.status['release'] = release
for module in release['modules']:
self.status['installing'] = module
self.status['progress'] = 0
self.status['size'] = 0
package_tar = release['modules'][module]['name']
url = self.url(package_tar)
package_tar = os.path.join(self.target, package_tar)
self.download(url, package_tar)
tar = tarfile.open(package_tar)
tar.extractall()
tar.close()
os.unlink(package_tar)
os.symlink('openmedialibrary/ctl', 'ctl')
self.status['progress'] = 0
self.status['installing'] = 'setup'
if sys.platform.startswith('linux'):
apt_packages = ''
dnf_packages = ''
try:
from PIL import Image
import lxml
except:
apt_packages += ' python3.4 python3-pil python3-lxml'
dnf_packages += ' python3-pillow python3-lxml'
version = '4.0'
distro = platform.linux_distribution()
if distro[0] == 'Ubuntu' and distro[1] <= '14.04':
version = '3.0'
try:
import gi
gi.require_version('WebKit2', version)
from gi.repository import WebKit2, Gtk
except:
apt_packages += ' gir1.2-webkit2-' + version
dnf_packages += ' webkitgtk4'
try:
import OpenSSL
except:
apt_packages += ' python3-openssl'
dnf_packages += ' python3-pyOpenSSL'
try:
import Crypto
except:
apt_packages += ' python3-crypto'
dnf_packages += ' python3-pyCrypto'
if not has_bin('pdftocairo'):
apt_packages += ' poppler-utils'
dnf_packages += ' poppler-utils'
if has_bin('apt-get') and apt_packages:
print('Installing additional packages: %s' % apt_packages)
os.system('sudo apt-get install -y ' + apt_packages)
elif has_bin('dnf') and dnf_packages:
print('Installing additional packages: %s' % dnf_packages)
os.system('sudo dnf install -y ' + dnf_packages)
else:
print('You need to install Pillow, lxml and pyOpenSSL\ni.e. sudo pip3 install pillow lxml pyOpenSSL')
if 'poppler' in apt_packages:
print('You need to install pdftocairo (part of poppler-utils)')
input("After installing those packages, press Enter to continue...")
os.system('./ctl install_launcher')
os.system('./ctl setup')
self.status['progress'] = 1
with open('config/release.json', 'w') as fd:
json.dump(release, fd, indent=2)
self.status['done'] = True
def download(self, url, filename):
makefolder(filename)
print(os.path.basename(filename))
with open(filename, 'wb') as f:
with closing(urlopen(url)) as u:
size = int(u.headers.get('content-length', 0))
self.status['size'] = size
available = 0
data = u.read(4096)
while data:
if size:
available += len(data)
self.status['progress'] = available/size
f.write(data)
data = u.read(4096)
def get_release(self):
with closing(urlopen(self.url('release.json'))) as u:
data = json.loads(u.read().decode('utf-8'))
return data
def url(self, url):
return self.base_url + url
def has_bin(cmd):
return subprocess.call(['which', cmd], stdout=subprocess.PIPE) == 0
if __name__ == '__main__':
if len(sys.argv) == 1:
if sys.platform == 'darwin':
target = os.path.expanduser('~/Library/Application Support/Open Media Libary')
elif sys.platform.startswith('linux'):
target = os.path.expanduser('~/.local/share/openmedialibrary')
else:
target = os.path.join(os.curdir, 'openmedialibrary')
elif len(sys.argv) != 2:
print('usage: %s [target]' % sys.argv[0])
sys.exit(1)
else:
target = sys.argv[1]
if os.path.exists(target):
print('%s exists, remove it before re-installing Open Media Library' % target)
sys.exit(1)
if sys.platform.startswith('linux'):
import platform
distro = platform.linux_distribution()
if distro[0] == 'Ubuntu' and distro[1] < '14.10':
try:
from OpenSSL.SSL import TLSv1_2_METHOD
except:
print("Open Media Library currently only works on Ubuntu 14.10 and later")
print("You can also install a current version of pyOpenSSL:\n\tsudo apt-get install python3-pip\n\tsudo pip3 install pyOpenSSL")
sys.exit(1)
install = Install(target)
install.join()
subprocess.call([os.path.join(target, 'ctl'), 'open'])