forked from 0x2620/pandora
use python3-venv
This commit is contained in:
parent
90537f2f0e
commit
8e4ba42fc1
13 changed files with 119 additions and 118 deletions
|
@ -29,8 +29,7 @@
|
|||
2) install all required packages
|
||||
|
||||
apt-get install git \
|
||||
python3-setuptools python3-pip python3-virtualenv \
|
||||
virtualenv ipython3 \
|
||||
python3-setuptools python3-pip python3-venv ipython3 \
|
||||
python3-dev python3-pil python3-numpy python3-psycopg2 \
|
||||
python3-pyinotify python3-simplejson \
|
||||
python3-geoip python3-html5lib python3-lxml \
|
||||
|
|
2
ctl
2
ctl
|
@ -9,7 +9,7 @@ fi
|
|||
if [ "$action" = "init" ]; then
|
||||
cd "`dirname "$0"`"
|
||||
BASE=`pwd`
|
||||
virtualenv --system-site-packages -p /usr/bin/python3 .
|
||||
python3 -m venv --system-site-packages .
|
||||
if [ ! -d static/oxjs ]; then
|
||||
git clone --depth 1 https://git.0x2620.org/oxjs.git static/oxjs
|
||||
fi
|
||||
|
|
|
@ -9,6 +9,7 @@ import ox
|
|||
from ox import sort_string
|
||||
from six import PY2
|
||||
|
||||
|
||||
def safe_filename(filename):
|
||||
filename = filename.replace(': ', '_ ')
|
||||
filename = filename.replace('/', '_')
|
||||
|
|
|
@ -3,6 +3,28 @@ import os
|
|||
import signal
|
||||
import sys
|
||||
|
||||
|
||||
def activate_venv(base):
|
||||
if os.path.exists(base):
|
||||
old_os_path = os.environ.get('PATH', '')
|
||||
bin_path = os.path.join(base, 'bin')
|
||||
if bin_path not in old_os_path:
|
||||
os.environ['PATH'] = os.path.join(base, 'bin') + os.pathsep + old_os_path
|
||||
site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
|
||||
prev_sys_path = list(sys.path)
|
||||
import site
|
||||
site.addsitedir(site_packages)
|
||||
sys.real_prefix = sys.prefix
|
||||
sys.prefix = base
|
||||
# Move the added items to the front of the path:
|
||||
new_sys_path = []
|
||||
for item in list(sys.path):
|
||||
if item not in prev_sys_path:
|
||||
new_sys_path.append(item)
|
||||
sys.path.remove(item)
|
||||
sys.path[:0] = new_sys_path
|
||||
|
||||
|
||||
class DelayedSignalHandler(object):
|
||||
def __init__(self, managed_signals):
|
||||
self.managed_signals = managed_signals
|
||||
|
@ -27,26 +49,22 @@ class DelayedSignalHandler(object):
|
|||
'''
|
||||
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
||||
os.chdir(root_dir)
|
||||
|
||||
# use python3 from virtualenv
|
||||
python3 = os.path.normpath(os.path.join(root_dir, '..', 'bin', 'python3'))
|
||||
if os.path.exists(python3) and sys.version_info[0] == 2:
|
||||
import subprocess
|
||||
cmd = [python3] + sys.argv
|
||||
with DelayedSignalHandler((signal.SIGINT, signal.SIGTERM, signal.SIGHUP)):
|
||||
exit_value = subprocess.call(cmd)
|
||||
sys.exit(exit_value)
|
||||
|
||||
# using virtualenv's activate_this.py to reorder sys.path
|
||||
activate_this = os.path.normpath(os.path.join(root_dir, '..', 'bin', 'activate_this.py'))
|
||||
with open(activate_this) as f:
|
||||
code = compile(f.read(), activate_this, 'exec')
|
||||
exec(code, dict(__file__=activate_this))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
||||
|
||||
# use python3 from venv
|
||||
venv_dir = os.path.normpath(os.path.join(root_dir, '..'))
|
||||
python3 = os.path.join(venv_dir, 'bin', 'python3')
|
||||
if os.path.exists(python3) and sys.version_info[0] == 2:
|
||||
import subprocess
|
||||
cmd = [python3] + sys.argv
|
||||
with DelayedSignalHandler((signal.SIGINT, signal.SIGTERM, signal.SIGHUP)):
|
||||
exit_value = subprocess.call(cmd)
|
||||
sys.exit(exit_value)
|
||||
|
||||
os.chdir(root_dir)
|
||||
activate_venv(venv_dir)
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
|
||||
from django.core.management import execute_from_command_line
|
||||
import settings
|
||||
|
|
|
@ -11,6 +11,9 @@ import djcelery
|
|||
djcelery.setup_loader()
|
||||
|
||||
BASE_DIR = PROJECT_ROOT = normpath(dirname(__file__))
|
||||
BIN_DIR = normpath(join(PROJECT_ROOT, '..', 'bin'))
|
||||
if BIN_DIR not in os.environ['PATH']:
|
||||
os.environ['PATH'] = BIN_DIR + os.pathsep + os.environ['PATH']
|
||||
|
||||
DEBUG = False
|
||||
JSON_DEBUG = False
|
||||
|
|
|
@ -1,25 +1,17 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
import os
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
# using virtualenv's activate_this.py to reorder sys.path
|
||||
activate_this = os.path.join(root_dir, 'bin', 'activate_this.py')
|
||||
if os.path.exists(activate_this):
|
||||
with open(activate_this) as f:
|
||||
code = compile(f.read(), activate_this, 'exec')
|
||||
exec(code, dict(__file__=activate_this))
|
||||
|
||||
from PIL import Image
|
||||
from optparse import OptionParser
|
||||
import sys
|
||||
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
||||
|
||||
|
||||
def render_icon(frame, timeline, icon):
|
||||
icon_width = 1024
|
||||
icon_height = 1024
|
||||
|
|
|
@ -1,26 +1,20 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
import os
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
# using virtualenv's activate_this.py to reorder sys.path
|
||||
activate_this = os.path.join(root_dir, 'bin', 'activate_this.py')
|
||||
if os.path.exists(activate_this):
|
||||
with open(activate_this) as f:
|
||||
code = compile(f.read(), activate_this, 'exec')
|
||||
exec(code, dict(__file__=activate_this))
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
from optparse import OptionParser
|
||||
from ox.image import drawText, wrapText
|
||||
import sys
|
||||
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
||||
|
||||
|
||||
def render_list_icon(frames, icon):
|
||||
icon_width = 256
|
||||
icon_height = 256
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
import os
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
# using virtualenv's activate_this.py to reorder sys.path
|
||||
activate_this = os.path.join(root_dir, 'bin', 'activate_this.py')
|
||||
if os.path.exists(activate_this):
|
||||
with open(activate_this) as f:
|
||||
code = compile(f.read(), activate_this, 'exec')
|
||||
exec(code, dict(__file__=activate_this))
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
import json
|
||||
|
@ -22,6 +13,7 @@ from ox.image import drawText, getRGB, getTextSize, wrapText
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
||||
|
||||
def get_frame(id, height, position):
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
import os
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
# using virtualenv's activate_this.py to reorder sys.path
|
||||
activate_this = os.path.join(root_dir, 'bin', 'activate_this.py')
|
||||
if os.path.exists(activate_this):
|
||||
with open(activate_this) as f:
|
||||
code = compile(f.read(), activate_this, 'exec')
|
||||
exec(code, dict(__file__=activate_this))
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
import json
|
||||
|
@ -21,6 +12,7 @@ import ox
|
|||
from ox.image import getRGB, drawText, wrapText
|
||||
import sys
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
||||
|
||||
def render_poster(data, poster):
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
import os
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
# using virtualenv's activate_this.py to reorder sys.path
|
||||
activate_this = os.path.join(root_dir, 'bin', 'activate_this.py')
|
||||
if os.path.exists(activate_this):
|
||||
with open(activate_this) as f:
|
||||
code = compile(f.read(), activate_this, 'exec')
|
||||
exec(code, dict(__file__=activate_this))
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
import json
|
||||
|
@ -21,6 +12,8 @@ import ox
|
|||
from ox.image import drawText, wrapText
|
||||
import sys
|
||||
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
||||
|
||||
def render_poster(data, poster):
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
import os
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
# using virtualenv's activate_this.py to reorder sys.path
|
||||
activate_this = os.path.join(root_dir, 'bin', 'activate_this.py')
|
||||
if os.path.exists(activate_this):
|
||||
with open(activate_this) as f:
|
||||
code = compile(f.read(), activate_this, 'exec')
|
||||
exec(code, dict(__file__=activate_this))
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
import json
|
||||
|
@ -21,6 +12,7 @@ import ox
|
|||
from ox.image import drawText, wrapText
|
||||
import sys
|
||||
|
||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
||||
|
||||
def render_poster(data, poster):
|
||||
|
|
92
update.py
92
update.py
|
@ -1,39 +1,74 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import json
|
||||
import os
|
||||
|
||||
base = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
||||
os.chdir(base)
|
||||
|
||||
# using virtualenv's activate_this.py to reorder sys.path
|
||||
activate_this = os.path.join(base, 'bin', 'activate_this.py')
|
||||
with open(activate_this) as f:
|
||||
code = compile(f.read(), activate_this, 'exec')
|
||||
exec(code, dict(__file__=activate_this))
|
||||
|
||||
import sys
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
try:
|
||||
from urllib.request import urlopen
|
||||
except:
|
||||
from urllib2 import urlopen
|
||||
import json
|
||||
from os.path import join, exists
|
||||
|
||||
|
||||
repos = {
|
||||
"pandora": {
|
||||
"url": "https://git.0x2620.org/pandora.git",
|
||||
"path": ".",
|
||||
},
|
||||
"oxjs": {
|
||||
"url": "https://git.0x2620.org/oxjs.git",
|
||||
"path": "./static/oxjs",
|
||||
},
|
||||
"oxtimelines": {
|
||||
"url": "https://git.0x2620.org/oxtimelines.git",
|
||||
"path": "./src/oxtimelines",
|
||||
},
|
||||
"python-ox": {
|
||||
"url": "https://git.0x2620.org/python-ox.git",
|
||||
"path": "./src/python-ox",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def activate_venv(base):
|
||||
if os.path.exists(base):
|
||||
old_os_path = os.environ.get('PATH', '')
|
||||
bin_path = os.path.join(base, 'bin')
|
||||
if bin_path not in old_os_path:
|
||||
os.environ['PATH'] = os.path.join(base, 'bin') + os.pathsep + old_os_path
|
||||
site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
|
||||
prev_sys_path = list(sys.path)
|
||||
import site
|
||||
site.addsitedir(site_packages)
|
||||
sys.real_prefix = sys.prefix
|
||||
sys.prefix = base
|
||||
# Move the added items to the front of the path:
|
||||
new_sys_path = []
|
||||
for item in list(sys.path):
|
||||
if item not in prev_sys_path:
|
||||
new_sys_path.append(item)
|
||||
sys.path.remove(item)
|
||||
sys.path[:0] = new_sys_path
|
||||
|
||||
|
||||
def run(*cmd):
|
||||
p = subprocess.Popen(cmd)
|
||||
p.wait()
|
||||
return p.returncode
|
||||
|
||||
|
||||
def get(*cmd):
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, error = p.communicate()
|
||||
return stdout.decode()
|
||||
|
||||
|
||||
def get_json(url):
|
||||
return json.loads(urlopen(url).read().decode())
|
||||
|
||||
|
||||
def get_release():
|
||||
if os.path.exists('.release'):
|
||||
url = open('.release').read().strip()
|
||||
|
@ -45,28 +80,11 @@ def get_release():
|
|||
print("Failed to load %s check your internet connection." % url)
|
||||
sys.exit(1)
|
||||
|
||||
repos = {
|
||||
"pandora": {
|
||||
"url": "https://git.0x2620.org/pandora.git",
|
||||
"path": ".",
|
||||
},
|
||||
"oxjs": {
|
||||
"url": "https://git.0x2620.org/oxjs.git",
|
||||
"path": "./static/oxjs",
|
||||
},
|
||||
"oxtimelines": {
|
||||
"url": "https://git.0x2620.org/oxtimelines.git",
|
||||
"path": "./src/oxtimelines",
|
||||
},
|
||||
"python-ox": {
|
||||
"url": "https://git.0x2620.org/python-ox.git",
|
||||
"path": "./src/python-ox",
|
||||
}
|
||||
}
|
||||
|
||||
def reload_notice(base):
|
||||
print('\nPlease restart pan.do/ra to finish the update:\n\tsudo %s/ctl reload\n' % base)
|
||||
|
||||
|
||||
def check_services(base):
|
||||
services = "pandora pandora-tasks pandora-encoding pandora-cron pandora-websocketd".split()
|
||||
for service in services:
|
||||
|
@ -83,24 +101,32 @@ def check_services(base):
|
|||
print('\tsudo service %s start' % service)
|
||||
print('')
|
||||
|
||||
|
||||
def update_service(service):
|
||||
print('Please install new init script for "%s" service:' % service)
|
||||
if os.path.exists('/etc/init/%s.conf'%service):
|
||||
if os.path.exists('/etc/init/%s.conf' % service):
|
||||
print('\tsudo cp %s/etc/init/%s.conf /etc/init/' % (base, service))
|
||||
if os.path.exists('/bin/systemctl'):
|
||||
print('\tsudo cp %s/etc/systemd/system/%s.service /etc/systemd/system/' % (base, service))
|
||||
print('\tsudo systemctl daemon-reload')
|
||||
print('\tsudo service %s restart' % service)
|
||||
|
||||
|
||||
def run_git(path, *args):
|
||||
cmd = ['git'] + list(args)
|
||||
env = {'GIT_DIR': '%s/.git' % path}
|
||||
return subprocess.check_output(cmd, env=env).decode().strip()
|
||||
|
||||
|
||||
def get_version(path):
|
||||
return run_git(path, 'rev-list', 'HEAD', '--count')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
base = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
||||
os.chdir(base)
|
||||
activate_venv(base)
|
||||
|
||||
if len(sys.argv) == 2 and sys.argv[1] in ('database', 'db'):
|
||||
os.chdir(join(base, 'pandora'))
|
||||
print('\nRunning "./manage.py migrate"\n')
|
||||
|
@ -144,7 +170,7 @@ if __name__ == "__main__":
|
|||
import pandora.settings
|
||||
with open('pandora/local_settings.py', 'r') as f:
|
||||
local_settings = f.read()
|
||||
if not 'BROKER_URL' in local_settings:
|
||||
if 'BROKER_URL' not in local_settings:
|
||||
broker_url = 'amqp://%s:%s@%s:%s/%s' % (
|
||||
getattr(pandora.settings, 'BROKER_USER', 'pandora'),
|
||||
getattr(pandora.settings, 'BROKER_PASSWORD', 'box'),
|
||||
|
|
|
@ -69,8 +69,7 @@ apt-get install -y \
|
|||
git \
|
||||
python3-setuptools \
|
||||
python3-pip \
|
||||
virtualenv \
|
||||
python3-virtualenv \
|
||||
python3-venv \
|
||||
python3-dev \
|
||||
python3-pil \
|
||||
python3-numpy \
|
||||
|
|
Loading…
Reference in a new issue