Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/scielo/bin/cfg/version.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
4.0.095 Teste 29/03/2018
========================
4.0.095 29/03/2018
==================
- Installation with proxy

- Markup XML
Expand Down
44 changes: 19 additions & 25 deletions src/scielo/bin/xml/app_modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
# coding=utf-8
import os

try:
from app_modules.app.config import app_texts
except Exception as e:
print(e)
from .app.config import app_texts

try:
from app_modules.app.config import app_caller
except Exception as e:
print(e)
from .app.config import app_caller

try:
from app_modules.generics import logger
except Exception as e:
print(e)
from .generics import logger
from app_modules.app.config import (
app_texts,
app_caller,
)
from app_modules.generics import (
logger,
encoding,
system,
)

try:
from app_modules.generics import encoding
except Exception as e:
print(e)
from .generics import encoding
from .app.config import (
app_texts,
app_caller,
)
from .generics import (
logger,
encoding,
system,
)


THIS_FILE_LOCATION = os.path.dirname(os.path.realpath(__file__)).replace('\\', '/')
THIS_LOCATION = encoding.decode(THIS_FILE_LOCATION, encoding.SYS_DEFAULT_ENCODING)

INVALID_APP_PATH = not str(THIS_LOCATION) == THIS_FILE_LOCATION

BIN_PATH = THIS_LOCATION + '/../..'
BIN_PATH = os.path.dirname(os.path.dirname(THIS_LOCATION))
BIN_XML_PATH = BIN_PATH + '/xml'
JAR_PATH = BIN_PATH + '/jar'
RELATIVE_JAR_PATH = JAR_PATH.replace(BIN_PATH, './..')
Expand Down Expand Up @@ -66,9 +66,3 @@
os.unlink(LOG_PATH+'/app_caller.log')
except:
pass


appcaller = app_caller.AppCaller(
logger.get_logger(LOG_PATH+'/app_caller.log', 'Environment'),
VENV_PATH,
REQUIREMENTS_FILE)
120 changes: 101 additions & 19 deletions src/scielo/bin/xml/app_modules/app/config/app_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, logger, venv_path, requirements_filename):
self.logger = logger
self.path = venv_path
self.requirements = Requirements(requirements_filename)
self.proxy = ProxyInfo(None)
self.proxy_info = ProxyInfo(None)
self.setUp()

def setUp(self):
Expand Down Expand Up @@ -99,17 +99,21 @@ def install_venv(self):
if self.path is not None:
if not self.installed:
commands = []
commands.extend(self.proxy.register_commands)
commands.extend(self.proxy_info.register_commands)
commands.append(
'python -m pip install {} -U pip'.format(
self.proxy_info.parameter)
)
commands.append(
'python -m pip install {} --upgrade pip'.format(
self.proxy.parameter)
self.proxy_info.parameter)
)
commands.append(
'pip install {} virtualenv'.format(self.proxy.parameter)
'pip install {} virtualenv'.format(self.proxy_info.parameter)
)
commands.append(u'virtualenv "{}"'.format(self.path))
for cmd in commands:
if 'teste' in self.proxy.parameter:
if 'teste' in self.proxy_info.parameter:
encoding.display_message('Executaria\n {}'.format(cmd))
else:
system.run_command(cmd)
Expand All @@ -122,7 +126,7 @@ def install_venv(self):

def install_requirements(self):
commands = self.requirements.install_commands(
self.proxy,
self.proxy_info,
uninstall=True)
self.execute_in_virtualenv(commands)

Expand All @@ -136,7 +140,7 @@ def execute_in_virtualenv(self, commands):
def _execute_inline(self, commands):
_commands = [item for item in commands if len(item) > 0]
cmd = self.sep.join(_commands)
display_cmd = self.proxy.hide_password(cmd)
display_cmd = self.proxy_info.hide_password(cmd)
self.logger.info(display_cmd)
if 'teste' in cmd:
encoding.display_message('Executaria\n {}'.format(cmd))
Expand All @@ -153,6 +157,27 @@ def deactivate(self):
system.run_command(self.deactivate_command, True)


class RealEnv(object):

def __init__(self, logger, requirements_filename):
self.logger = logger
self.requirements = Requirements(requirements_filename)
self.proxy_info = ProxyInfo(None)

def install_requirements(self):
commands = self.requirements.install_commands(
self.proxy_info,
uninstall=True)
self.execute_commands(commands)

def execute_commands(self, commands):
for cmd in commands:
display_cmd = self.proxy_info.hide_password(cmd)
self.logger.info(display_cmd)
encoding.display_message(display_cmd)
os.system(cmd)


class Requirements(object):

def __init__(self, requirements_file):
Expand All @@ -163,6 +188,10 @@ def install_commands(self, proxy, uninstall):
if uninstall is True:
commands = self.uninstall_commands()
commands.extend(proxy.register_commands)
commands.append(
'python -m pip install {} -U pip'.format(
proxy.parameter)
)
commands.append(
'python -m pip install {} --upgrade pip'.format(
proxy.parameter)
Expand All @@ -179,30 +208,83 @@ def uninstall_commands(self):
return commands


class AppCaller(object):
class VEnvAppCaller(object):

def __init__(self, logger, venv_path, req_file):
self.venv = VirtualEnv(logger, venv_path, req_file)
self.environment = VirtualEnv(logger, venv_path, req_file)

@property
def proxy(self):
return self.venv.proxy
def proxy_info(self):
return self.environment.proxy_info

@proxy.setter
def proxy(self, value):
self.venv.proxy = ProxyInfo(value)
@proxy_info.setter
def proxy_info(self, _proxy_info):
self.environment.proxy_info = _proxy_info

def install_virtualenv(self, recreate=False):
inform('Install virtualenv')
self.venv.install_venv()
if self.venv.installed:
self.environment.install_venv()
if self.environment.installed:
inform('Install virtualenv: done!')

def install_requirements(self):
if self.venv.installed:
if self.environment.installed:
inform('Install Requirements')
self.venv.install_requirements()
self.environment.install_requirements()
#inform('Install Requirements: done!')

def execute(self, commands):
self.venv.execute_in_virtualenv(commands)
self.environment.execute_in_virtualenv(commands)


class RealAppCaller(object):

def __init__(self, logger, venv_path, req_file):
self.environment = RealEnv(logger, req_file)

@property
def proxy_info(self):
return self.environment.proxy_info

@proxy_info.setter
def proxy_info(self, _proxy_info):
self.environment.proxy_info = _proxy_info

def install_virtualenv(self, recreate=False):
pass

def install_requirements(self):
self.environment.install_requirements()

def execute(self, commands):
self.environment.execute_commands(commands)


class AppCaller(object):

def __init__(self, logger, venv_path, req_file):
self.caller = None
if venv_path is not None:
virtual = VEnvAppCaller(logger, venv_path, req_file)
virtual.install_virtualenv(True)
if virtual.environment.installed:
self.caller = virtual
if self.caller is None:
self.caller = RealAppCaller(logger, venv_path, req_file)

@property
def proxy_data(self):
return self.caller.proxy_info

@proxy_data.setter
def proxy_data(self, _proxy_data):
self.caller.proxy_info = ProxyInfo(_proxy_data)

def install_virtualenv(self, recreate=False):
self.caller.install_virtualenv(recreate)

def install_requirements(self):
self.caller.install_requirements()

def execute(self, commands):
self.caller.execute(commands)
4 changes: 4 additions & 0 deletions src/scielo/bin/xml/app_modules/app/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,9 @@ def coded_table_required(self):
def BLOCK_DISAGREEMENT_WITH_COLLECTION_CRITERIA(self):
return self.is_activated('BLOCK_DISAGREEMENT_WITH_COLLECTION_CRITERIA')

@property
def USE_VIRTUAL_ENV(self):
return self.is_activated('USE_VIRTUAL_ENV')

def is_activated(self, label, default='TRUE'):
return self._data.get(label, default).upper() in ['ON', 'TRUE', 'YES']
2 changes: 1 addition & 1 deletion src/scielo/bin/xml/app_modules/generics/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ def command_proxy_parameter(command):
def proxy_password(param):
if ':' in param and '@' in param:
p = param[param.find(':'):]
p = p[:p.find('@')+1]
p = p[:p.rfind('@')+1]
return p
37 changes: 29 additions & 8 deletions src/scielo/bin/xml/run_app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import sys

from app_modules.generics import encoding
from app_modules.generics import system
from app_modules.__init__ import appcaller
from app_modules.__init__ import BIN_XML_PATH
from app_modules.app.config import config
from app_modules.generics import (
encoding,
system,
logger,
)
from app_modules.app.config import (
app_caller,
config,
)
from app_modules.__init__ import (
BIN_XML_PATH,
LOG_PATH,
VENV_PATH,
REQUIREMENTS_FILE,
)


configuration = config.Configuration()

# proxy_data = system.proxy_data(configuration.proxy_info)

appcaller = app_caller.AppCaller(
logger.get_logger(LOG_PATH+'/app_caller.log', 'Environment'),
VENV_PATH if configuration.USE_VIRTUAL_ENV is True else None,
REQUIREMENTS_FILE
)


def execute(parameters):
Expand Down Expand Up @@ -46,9 +67,9 @@ def main(parameters):
from app_modules.app import xc
xc.call_converter(argv, '1.1')
elif parameters[1] == 'install':
configuration = config.Configuration()
proxy_info = configuration.proxy_info
appcaller.proxy = system.proxy_data(proxy_info)
# configuration = config.Configuration()
# proxy_info = configuration.proxy_info
appcaller.proxy_data = system.proxy_data(configuration.proxy_info)
appcaller.install_virtualenv(True)
appcaller.install_requirements()
else:
Expand Down