Skip to content

Commit

Permalink
Deployment of python port package working properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed May 31, 2019
1 parent 139d0fb commit 74cd07a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
Expand Up @@ -4,7 +4,6 @@
import shutil
import tarfile
import subprocess

import requests

def file_size(num, suffix='B'):
Expand All @@ -14,7 +13,6 @@ def file_size(num, suffix='B'):
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)


def find_assets(patterns):
api_url = 'https://api.github.com/repos/metacall/core/releases/latest'
urls = []
Expand All @@ -26,7 +24,6 @@ def find_assets(patterns):
urls.append(list(filter(regex.search, data))[0])
return urls


def download(urls):
for url in urls:
filename = '/tmp/{}'.format(url.split("/")[-1])
Expand Down Expand Up @@ -59,28 +56,24 @@ def download(urls):

os.rename(filename + '.tmp', filename)


def unpack(files):
for filename in files:
filename = filename.split("/")[-1]
print('Extracting {} ...'.format(filename))
with tarfile.open(filename) as file:
file.extractall()


def write_install_log(content):
with open('/tmp/mc-install.tmp', 'w') as logger:
logger.write('\n'.join(content))

shutil.move('/tmp/mc-install.tmp', '/usr/local/share/metacall/install')


def read_install_log():
with open('/usr/local/share/metacall/install', 'r') as logger:
lines = logger.read().splitlines()
return lines


def overwrite(src, dest):
if os.path.isdir(src):
if not os.path.isdir(dest):
Expand All @@ -93,23 +86,19 @@ def overwrite(src, dest):
shutil.copyfile(src, dest)
yield str(dest)


def spawn(args):
process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()

return output, error, process.returncode


def pre_install(components):
download(['https://raw.githubusercontent.com/metacall/core/develop/tools/metacall-runtime.sh'])
args = ['bash', '/tmp/metacall-runtime.sh']
args = args + components
subprocess.call(args)


def pre_install_prompt():

answers = {'yes': True, 'y': True, 'no': False, 'n': False}
components = ['python', 'ruby', 'netcore', 'v8', 'nodejs', 'ports']
args = []
Expand All @@ -133,7 +122,6 @@ def pre_install_prompt():
except KeyboardInterrupt:
exit(1)


def install(ignore=False):
if ignore is False:
if os.path.isfile('/usr/local/bin/metacallcli'):
Expand Down Expand Up @@ -194,11 +182,9 @@ def install(ignore=False):
except KeyboardInterrupt:
print('\nCanceled by user.')


def update():
install(ignore=True)


def uninstall(paths):

for fp in paths:
Expand All @@ -212,7 +198,6 @@ def uninstall(paths):

exit(0)


def uninstall_prompt():
paths = read_install_log()
message = '''This action would remove:\n {}
Expand All @@ -236,4 +221,4 @@ def uninstall_prompt():
else:
sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")
except KeyboardInterrupt:
exit(1)
exit(1)
15 changes: 10 additions & 5 deletions source/ports/py_port/package/metacall/__init__.py
Expand Up @@ -3,12 +3,17 @@
import os
import sys

# TODO: This is a nasty mock. It only will work if python port library (binary) is already installed and the
# environment variable correctly set up. This must be removed when metacall is correctly distributed
# and we can automate all distributions for all architectures, operative systems and all ports for all languages
sys.path.append(os.environ['PORT_LIBRARY_PATH']);
port_path = os.environ.get('PORT_LIBRARY_PATH')

if not port_path:
port_path = '/usr/local/lib'

sys.path.append(port_path);

try:
from _py_port import *
except ImportError:
from _py_portd import *
try:
from _py_portd import *
except ImportError:
pass
8 changes: 4 additions & 4 deletions source/ports/py_port/package/setup.py
Expand Up @@ -23,7 +23,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.1.9',
version='0.1.11',

description='A library for providing inter-language foreign function interface calls',
long_description=long_description,
Expand Down Expand Up @@ -109,9 +109,9 @@
# pip to create the appropriate form of executable for the target platform.
entry_points={
'console_scripts': [
'metacall-install=helper:install',
'metacall-uninstall=helper:uninstall_prompt',
'metacall-update=helper:update'
'metacall-install=metacall.__helper__:install',
'metacall-uninstall=metacall.__helper__:uninstall_prompt',
'metacall-update=metacall.__helper__:update'
],
},
)

0 comments on commit 74cd07a

Please sign in to comment.