Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_environment():
dest_dir = os.path.join(DIRNAME, CONFIG['virtualenv']['dest_dir'])
dest_dir = os.path.abspath(dest_dir)
# Create new virtual environment
print('Step 1. Create new virtual environment')
if not os.path.isdir(dest_dir) or CONFIG['virtualenv']['clear']:
kwargs = copy.copy(CONFIG['virtualenv'])
kwargs['home_dir'] = kwargs['dest_dir']
verbosity = int(kwargs['verbose']) - int(kwargs['quiet'])
logger = virtualenv.Logger([
(virtualenv.Logger.level_for_integer(2 - verbosity), sys.stdout),
])
del kwargs['dest_dir'], kwargs['quiet'], kwargs['verbose']
virtualenv.logger = logger
virtualenv.create_environment(**kwargs)
else:
print('Virtual environment %r already exists.' % \
CONFIG['virtualenv']['dest_dir'])
def create(self):
# Create new virtual environment
print('\nStep 1. Create new virtual environment')
if not os.path.isdir(self.dest_dir) or CONFIG['virtualenv']['clear']:
kwargs = copy.copy(CONFIG['virtualenv'])
kwargs['home_dir'] = self.dest_dir
verbosity = int(kwargs['verbose']) - int(kwargs['quiet'])
logger = virtualenv.Logger([
(virtualenv.Logger.level_for_integer(2 - verbosity),
sys.stdout),
])
del kwargs['dest_dir'], kwargs['quiet'], kwargs['verbose']
virtualenv.logger = logger
virtualenv.create_environment(**kwargs)
else:
print('Virtual environment %r already exists.' % self.dest_dir)
dest='distribute',
action='store_true',
help="Backward compatibility. Does nothing.")
if 'extend_parser' in globals():
extend_parser(parser)
options, args = parser.parse_args()
global logger
if 'adjust_options' in globals():
adjust_options(options, args)
verbosity = options.verbose - options.quiet
logger = Logger([(Logger.level_for_integer(2 - verbosity), sys.stdout)])
if options.python and not os.environ.get('VIRTUALENV_INTERPRETER_RUNNING'):
env = os.environ.copy()
interpreter = resolve_interpreter(options.python)
if interpreter == sys.executable:
logger.warn('Already using interpreter %s' % interpreter)
else:
logger.notify('Running virtualenv with interpreter %s' % interpreter)
env['VIRTUALENV_INTERPRETER_RUNNING'] = 'true'
file = __file__
if file.endswith('.pyc'):
file = file[:-1]
popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
raise SystemExit(popen.wait())
if not args:
'--prompt',
dest='prompt',
help='Provides an alternative prompt prefix for this environment')
if 'extend_parser' in globals():
extend_parser(parser)
options, args = parser.parse_args()
global logger
if 'adjust_options' in globals():
adjust_options(options, args)
verbosity = options.verbose - options.quiet
logger = Logger([(Logger.level_for_integer(2 - verbosity), sys.stdout)])
if options.python and not os.environ.get('VIRTUALENV_INTERPRETER_RUNNING'):
env = os.environ.copy()
interpreter = resolve_interpreter(options.python)
if interpreter == sys.executable:
logger.warn('Already using interpreter %s' % interpreter)
else:
logger.notify('Running virtualenv with interpreter %s' % interpreter)
env['VIRTUALENV_INTERPRETER_RUNNING'] = 'true'
file = __file__
if file.endswith('.pyc'):
file = file[:-1]
popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
raise SystemExit(popen.wait())
# Force --distribute on Python 3, since setuptools is not available.
finally:
sys.argv[:] = orig_argv
else:
try:
import virtualenv
except ImportError:
raise errors.DistutilsModuleError(
'The virtualenv module must be available if no virtualenv '
'bootstrap script is given: {0}'.format(bootstrap))
self.logger.info(
'Setting up a isolated Python with module: '
'{0}.create_environment({1} {2})'.format(
virtualenv, repr(home_dir), ' '.join(
'{0}={1}'.format(item) for item in opts.items())))
virtualenv.logger = virtualenv.Logger([(
virtualenv.Logger.level_for_integer(2 - self.verbose),
sys.stdout)])
virtualenv.create_environment(home_dir, **opts)
return os.path.join(
sysconfig.get_path('scripts', vars=dict(base=home_dir)),
'python' + sysconfig.get_config_var('EXE'))
def reset_python_environment(self):
"""
Reset the python environment.
"""
path = self.root_path
if not exists(path):
return False
virtualenv.logger = virtualenv.Logger(
[(virtualenv.Logger.level_for_integer(2), sys.stdout)])
virtualenv.create_environment(path, site_packages=False)
return True
def create_environment(path, config_ori):
"""Create environment structure.
"""
# Archivo de configuracion destino
config_dst = join(path, 'etc', config_filename)
if not exists(path) or not listdir(path):
# Crea el ambiente python
virtualenv.logger = virtualenv.Logger(
[(virtualenv.Logger.level_for_integer(2), sys.stdout)])
virtualenv.create_environment(path, site_packages=False)
# Crea el directorio donde va el archivo de configuracion
makedirs(dirname(config_dst))
# Descarga el archivo de configuracion environment.yml
urlretrieve(config_ori, config_dst)
# Prepara el ambiente Odoo
env = OdooEnvironment(path)
env.setup()
return env