Skip to content

Commit

Permalink
Merge pull request #238 from QualiSystems/feature_python_3_support
Browse files Browse the repository at this point in the history
Feature python 3 support
  • Loading branch information
alexquali authored Aug 19, 2019
2 parents 5a758ec + 4c286dc commit f73ba7e
Show file tree
Hide file tree
Showing 42 changed files with 212 additions and 132 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
=======
History
=======

1.2.11 (2019-08-14)
-------------------

* Added Python 3 support

1.2.10 (2019-04-22)
-------------------

Expand Down
6 changes: 2 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
requests
cookiecutter
qpm
click==6.7
pyyaml
terminaltables
cloudshell-rest-api>=8.2.2.0
colorama
giturlparse.py
ruamel.yaml==0.15.33
cryptography==2.1.4
setuptools>=39.0.0
ruamel.yaml
cryptography
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.2.10
current_version = 1.2.11
commit = True
tag = False

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def get_file_content(file_name):
keywords='shellfoundry sandbox cloud virtualization vcenter cmp cloudshell quali command-line cli',
classifiers=[
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 2.7",
# "Programming Language :: Python :: 2.7",
"Topic :: Software Development :: Libraries",
"License :: OSI Approved :: Apache Software License",
],
python_requires='>=2.7, <3.0.*',
# python_requires='>=2.7, <3.0.*',
test_suite='tests',
tests_require=get_file_content('test_requirements.txt')
)
2 changes: 1 addition & 1 deletion shellfoundry/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


"""bootstrap.cli: executed when bootstrap directory is called as script."""
from bootstrap import cli
from .bootstrap import cli
cli()

# Alternative way to create the script which supports arguments
Expand Down
32 changes: 17 additions & 15 deletions shellfoundry/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def version():
"""
Displays the shellfoundry version
"""
click.echo(u'shellfoundry version ' + pkg_resources.get_distribution(u'shellfoundry').version)
click.echo('shellfoundry version ' + pkg_resources.get_distribution('shellfoundry').version)


@cli.command()
@click.option(u'--gen2', 'default_view', flag_value=GEN_TWO, help="Show 2nd generation shell templates")
@click.option(u'--gen1', 'default_view', flag_value=GEN_ONE, help="Show 1st generation shell templates")
@click.option(u'--layer1', 'default_view', flag_value=LAYER_ONE, help="Show layer1 shell templates")
@click.option(u'--all', 'default_view', flag_value=NO_FILTER, help="Show all templates")
@click.option('--gen2', 'default_view', flag_value=GEN_TWO, help="Show 2nd generation shell templates")
@click.option('--gen1', 'default_view', flag_value=GEN_ONE, help="Show 1st generation shell templates")
@click.option('--layer1', 'default_view', flag_value=LAYER_ONE, help="Show layer1 shell templates")
@click.option('--all', 'default_view', flag_value=NO_FILTER, help="Show all templates")
@shellfoundry_version_check(abort_if_major=True)
def list(default_view):
"""
Expand All @@ -46,16 +46,18 @@ def list(default_view):


@cli.command()
@click.argument(u'name')
@click.option(u'--template', default=u'gen2/resource',
@click.argument('name')
@click.option('--template', default='gen2/resource',
help="Specify a Shell template. Use 'shellfoundry list' to see the list of available templates. "
"You can use 'local://<folder>' to specify a locally saved template")
@click.option(u'--version', default=None)
@click.option('--version', default=None)
@click.option('--python', type=click.Choice(['2', '3']), default=None, required=False,
help="Specify Python version which will be used")
@shellfoundry_version_check(abort_if_major=True)
def new(name, template, version):
def new(name, template, version, python):
""" Creates a new shell based on a template """

NewCommandExecutor().new(name, template, version)
NewCommandExecutor().new(name, template, version, python)


@cli.command()
Expand Down Expand Up @@ -92,7 +94,7 @@ def generate():


@cli.command()
@click.argument(u'kv', type=(str, str), default=(None, None), required=False)
@click.argument('kv', type=(str, str), default=(None, None), required=False)
@click.option('--global/--local', 'global_cfg', default=True)
@click.option('--remove', 'key_to_remove', default=None)
def config(kv, global_cfg, key_to_remove):
Expand All @@ -102,7 +104,7 @@ def config(kv, global_cfg, key_to_remove):


@cli.command()
@click.argument(u'template_name')
@click.argument('template_name')
def show(template_name):
""" Shows all versions of TEMPLATE NAME """

Expand All @@ -111,7 +113,7 @@ def show(template_name):

@cli.command()
# @click.argument(u'name', type=str, default="", required=False)
@click.argument(u'source')
@click.argument('source')
@click.option('--attribute', 'add_attribute', multiple=True, default=None, help="Creates a commented out attribute in the shell definition")
# @click.option('--command', 'add_command', multiple=True, default=None, help="Creates a commented out new command template to be filled by the developer")
# @click.option('--edit', 'edit_command', multiple=True, default=None, help="Copy the full command logic to the driver")
Expand All @@ -125,7 +127,7 @@ def extend(source, add_attribute):
ExtendCommandExecutor().extend(source, add_attribute)

@cli.command()
@click.argument(u'cs_version')
@click.argument('cs_version')
@click.option('--output_dir', 'output_dir', default=None, help="Folder where templates will be saved")
def get_templates(cs_version, output_dir):
""" Download all templates which are compatible with provided CloudShell Version
Expand All @@ -136,7 +138,7 @@ def get_templates(cs_version, output_dir):
GetTemplatesCommandExecutor().get_templates(cs_version, output_dir)

@cli.command()
@click.argument(u'name')
@click.argument('name')
def delete(name):
""" Deletes the shell from CloudShell
Expand Down
2 changes: 1 addition & 1 deletion shellfoundry/commands/config_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _echo_config(self, config_file_path):
def _format_config_as_table(self, config_data, defaults_char):
from shellfoundry.utilities.modifiers.configuration.password_modification import PasswordModification
table_data = [['Key', 'Value', '']]
for key, value in config_data[INSTALL].iteritems():
for key, value in config_data[INSTALL].items():
default_val = ''
if defaults_char in value:
default_val = defaults_char
Expand Down
9 changes: 8 additions & 1 deletion shellfoundry/commands/delete_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@

import click
from shellfoundry.utilities.shell_package_installer import ShellPackageInstaller
from shellfoundry.exceptions import FatalError


class DeleteCommandExecutor(object):
def __init__(self, shell_package_installer=None):
self.shell_package_installer = shell_package_installer or ShellPackageInstaller()

def delete(self, shell_name):
self.shell_package_installer.delete(shell_name=shell_name)
try:
self.shell_package_installer.delete(shell_name=shell_name)
except FatalError as err:
msg = err.message if hasattr(err, "message") else err.args[0]
# print(type(err.args), err.args)
click.ClickException(msg)

click.secho('Successfully deleted shell', fg='green')
8 changes: 4 additions & 4 deletions shellfoundry/commands/extend_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ def extend(self, source, attribute_names):
raise click.ClickException(err.message)
except Exception:
# raise
raise click.BadParameter(u"Check correctness of entered attributes")
raise click.BadParameter("Check correctness of entered attributes")

# Remove shell version from folder name
shell_path = re.sub(r"-\d+(\.\d+)*/?$", "", temp_shell_path)
os.rename(temp_shell_path, shell_path)

if not self.shell_gen_validations.validate_2nd_gen(shell_path):
raise click.ClickException(u"Invalid second generation Shell.")
raise click.ClickException("Invalid second generation Shell.")

modificator = DefinitionModification(shell_path)
self._unpack_driver_archive(shell_path, modificator)
Expand Down Expand Up @@ -124,9 +124,9 @@ def _unpack_driver_archive(self, shell_path, modificator=None):
if not modificator:
modificator = DefinitionModification(shell_path)

artifacts = modificator.get_artifacts_files(artifact_name_list=self.ARTIFACTS.keys())
artifacts = modificator.get_artifacts_files(artifact_name_list=list(self.ARTIFACTS.keys()))

for artifact_name, artifact_path in artifacts.iteritems():
for artifact_name, artifact_path in artifacts.items():

artifact_path = os.path.join(shell_path, artifact_path)

Expand Down
4 changes: 2 additions & 2 deletions shellfoundry/commands/get_templates_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_templates(self, cs_version, output_dir=None):
if online_mode:
try:
response = self.template_retriever._get_templates_from_github()
config = yaml.load(response)
config = yaml.safe_load(response)
repos = set(template["repository"] for template in config["templates"])

if not output_dir:
Expand Down Expand Up @@ -111,5 +111,5 @@ def download_template(self, repository, cs_version, templates_path, github_login
finally:
pass

except click.ClickException, err:
except click.ClickException as err:
errors.append(err.message)
14 changes: 9 additions & 5 deletions shellfoundry/commands/install_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

import click
import os

from urllib2 import HTTPError, URLError
try:
# Python 2.x version
from urllib2 import HTTPError, URLError
except:
# Python 3.x version
from urllib.error import HTTPError, URLError

from shellfoundry.exceptions import FatalError
from shellfoundry.utilities.config_reader import Configuration, CloudShellConfigReader
Expand Down Expand Up @@ -43,12 +47,12 @@ def _install_old_school_shell(self):
self.installer.install(shell_config.name, cloudshell_config)
except HTTPError as e:
if e.code == 401:
raise FatalError(u'Login to CloudShell failed. Please verify the credentials in the config')
raise FatalError('Login to CloudShell failed. Please verify the credentials in the config')
error = e.msg
except URLError:
raise FatalError(u'Connection to CloudShell Server failed. Please make sure it is up and running properly.')
raise FatalError('Connection to CloudShell Server failed. Please make sure it is up and running properly.')
except Exception as e:
error = e.message

if error:
raise FatalError(u"Failed to install shell. CloudShell responded with: '{}'".format(error))
raise FatalError("Failed to install shell. CloudShell responded with: '{}'".format(error))
4 changes: 2 additions & 2 deletions shellfoundry/commands/list_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def list(self):
"available templates and standards are not compatible")

template_rows = [["Template Name", "CloudShell Ver.", "Description"]]
for template in templates.values():
for template in list(templates.values()):
template = template[0]
cs_ver_txt = str(template.min_cs_ver) + " and up"
template_rows.append(
Expand All @@ -74,7 +74,7 @@ def list(self):
return

row = 1
for template in templates.values():
for template in list(templates.values()):
template = template[0]
wrapped_string = linesep.join(wrap(template.description, max_width))
table.table_data[row][2] = wrapped_string
Expand Down
Loading

0 comments on commit f73ba7e

Please sign in to comment.