Skip to content

Commit

Permalink
Merge pull request #236 from tommydeboer/fix/debugger
Browse files Browse the repository at this point in the history
Rename io to in_out to fix broken debug connection
  • Loading branch information
tommydeboer authored Jun 17, 2022
2 parents de610d3 + fd81340 commit b352e10
Show file tree
Hide file tree
Showing 36 changed files with 165 additions and 165 deletions.
8 changes: 4 additions & 4 deletions mcmd/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from mcmd.core.context.home_context import HomeContext
from mcmd.args.parser import parse_args
from mcmd.config.loader import load_config
from mcmd.io import io
from mcmd.io.io import set_debug
from mcmd.io.logging import set_level
from mcmd.in_out import in_out
from mcmd.in_out.in_out import set_debug
from mcmd.in_out.logging import set_level


def main():
Expand Down Expand Up @@ -69,7 +69,7 @@ def set_log_level(args):

# noinspection PyUnusedLocal
def interrupt_handler(sig, frame):
io.warn('Interrupted by user.')
in_out.warn('Interrupted by user.')
sys.exit(0)


Expand Down
22 changes: 11 additions & 11 deletions mcmd/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from mcmd.core.compatibility import version, deprecated
from mcmd.core.context import context
from mcmd.core.errors import McmdError
from mcmd.io import io
from mcmd.io.io import highlight
from mcmd.in_out import in_out
from mcmd.in_out.in_out import highlight
from mcmd.molgenis import api
from mcmd.molgenis.client import post, get, post_files
from mcmd.molgenis.principals import to_role_name
Expand Down Expand Up @@ -169,7 +169,7 @@ def add_arguments(subparsers):

@command
def add_user(args):
io.start('Adding user %s' % highlight(args.username))
in_out.start('Adding user %s' % highlight(args.username))

password = args.set_password if args.set_password else args.username
email = args.with_email if args.with_email else args.username + '@molgenis.org'
Expand All @@ -190,7 +190,7 @@ def add_user(args):
@command
def add_role(args):
role_name = to_role_name(args.rolename)
io.start('Adding role {}'.format(highlight(role_name)))
in_out.start('Adding role {}'.format(highlight(role_name)))

role = {'name': role_name,
'label': role_name}
Expand Down Expand Up @@ -241,7 +241,7 @@ def _get_role_ids(role_names) -> List[str]:
@command
def add_group(args):
group_name = _to_group_name(args.name)
io.start('Adding group %s' % highlight(group_name))
in_out.start('Adding group %s' % highlight(group_name))
post(api.group(), data={'name': group_name, 'label': args.name})


Expand All @@ -259,7 +259,7 @@ def _to_group_name(group_input: str):

@command
def add_package(args):
io.start('Adding package %s' % highlight(args.id))
in_out.start('Adding package %s' % highlight(args.id))

data = {'id': args.id,
'label': args.id}
Expand All @@ -272,7 +272,7 @@ def add_package(args):

@command
def add_token(args):
io.start('Adding token %s for user %s' % (highlight(args.token), highlight(args.user)))
in_out.start('Adding token %s for user %s' % (highlight(args.token), highlight(args.user)))

user = get(api.rest2('sys_sec_User'),
params={
Expand Down Expand Up @@ -312,12 +312,12 @@ def add_theme(args):
paths.append(bs4)
names.append('bootstrap4-style')
bs4_name = file_utils.get_file_name_from_path(bs4)
io.start(
in_out.start(
'Adding bootstrap 3 theme {} and bootstrap 4 theme {} to bootstrap themes'.format(
highlight(bs3_name),
highlight(bs4_name)))
else:
io.start(
in_out.start(
'Adding bootstrap 3 theme {} to bootstrap themes'.format(
highlight(bs3_name)))
if not args.from_path:
Expand All @@ -337,10 +337,10 @@ def add_logo(args):
valid_types = {'image/jpeg', 'image/png', 'image/gif'}
logo = [args.logo]
if not args.from_path:
io.start('Adding logo from path {}'.format(highlight(args.logo)))
in_out.start('Adding logo from path {}'.format(highlight(args.logo)))
logo = [_get_path_from_quick_folders(args.logo)]
else:
io.start('Adding logo {}'.format(highlight(args.logo)))
in_out.start('Adding logo {}'.format(highlight(args.logo)))
files = _prepare_files_for_upload(logo, ['logo'], valid_types)
post_files(files, api_)

Expand Down
20 changes: 10 additions & 10 deletions mcmd/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from mcmd.commands._registry import arguments
from mcmd.core.command import command, CommandType
from mcmd.core.errors import McmdError
from mcmd.io import io, ask
from mcmd.io.io import highlight
from mcmd.in_out import in_out, ask
from mcmd.in_out.in_out import highlight


# =========
Expand Down Expand Up @@ -126,7 +126,7 @@ def config_set_host(args):
urls = [auth['url'] for auth in auths]
url = ask.multi_choice('Please select a host:', urls)

io.start("Switching to host {}".format(highlight(url)))
in_out.start("Switching to host {}".format(highlight(url)))

if config.host_exists(url):
config.set_host(url)
Expand All @@ -143,21 +143,21 @@ def config_set_import_action(args):
options = ['add', 'add_update_existing', 'update']
action = ask.multi_choice('Choose the default import action:', options)

io.start("Setting import action to {}".format(highlight(action)))
in_out.start("Setting import action to {}".format(highlight(action)))
config.set_import_action(action)


# noinspection PyUnusedLocal
@command
def config_set_non_interactive(args):
io.start('Switching to non-interactive mode')
in_out.start('Switching to non-interactive mode')
config.set_non_interactive(True)


# noinspection PyUnusedLocal
@command
def config_set_interactive(args):
io.start('Switching to interactive mode')
in_out.start('Switching to interactive mode')
config.set_non_interactive(False)


Expand All @@ -184,9 +184,9 @@ def config_add_host(args):
password = ask.password("Password (Leave blank to use command line authentication)")
password = None if len(password) == 0 else password

io.start("Adding host {}".format(highlight(url)))
in_out.start("Adding host {}".format(highlight(url)))
config.add_host(url, username, password)
io.succeed()
in_out.succeed()

if args.switch:
_switch_to_new_host(url)
Expand All @@ -196,15 +196,15 @@ def config_add_host(args):

@command
def config_add_dataset_folder(args):
io.start('Adding resource folder {}'.format(highlight(args.folder)))
in_out.start('Adding resource folder {}'.format(highlight(args.folder)))
if not Path(args.folder).is_dir():
raise McmdError('Folder does not exist: {}'.format(args.folder))
config.add_dataset_folder(args.folder)


@command
def config_add_resource_folder(args):
io.start('Adding resource folder {}'.format(highlight(args.folder)))
in_out.start('Adding resource folder {}'.format(highlight(args.folder)))
if not Path(args.folder).is_dir():
raise McmdError('Folder does not exist: {}'.format(args.folder))
config.add_resource_folder(args.folder)
Expand Down
28 changes: 14 additions & 14 deletions mcmd/commands/delete.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from urllib.parse import urljoin

import mcmd.io.ask
import mcmd.in_out.ask
import mcmd.molgenis.client as client
from mcmd.commands._registry import arguments
from mcmd.core.command import command
from mcmd.io import io
from mcmd.io.io import highlight
from mcmd.in_out import in_out
from mcmd.in_out.in_out import highlight
from mcmd.molgenis import api
from mcmd.molgenis.resources import detect_resource_type, ensure_resource_exists, ResourceType

Expand Down Expand Up @@ -79,23 +79,23 @@ def delete(args):


def _delete_entity_type(args):
if args.force or (not args.force and mcmd.io.ask.confirm(
if args.force or (not args.force and mcmd.in_out.ask.confirm(
'Are you sure you want to delete entity type {} including its data?'.format(args.resource))):
io.start('Deleting entity type {}'.format(highlight(args.resource)))
in_out.start('Deleting entity type {}'.format(highlight(args.resource)))
_delete_rows(ResourceType.ENTITY_TYPE.get_entity_id(), [args.resource])


def _delete_entity_type_data(args):
if args.force or (not args.force and mcmd.io.ask.confirm(
if args.force or (not args.force and mcmd.in_out.ask.confirm(
'Are you sure you want to delete all data in entity type {}?'.format(args.resource))):
io.start('Deleting all data from entity {}'.format(highlight(args.resource)))
in_out.start('Deleting all data from entity {}'.format(highlight(args.resource)))
client.delete(api.rest1(args.resource))


def _delete_entity_type_attribute(args):
if args.force or (not args.force and mcmd.io.ask.confirm(
if args.force or (not args.force and mcmd.in_out.ask.confirm(
'Are you sure you want to delete attribute {} of entity type {}?'.format(args.attribute, args.resource))):
io.start('Deleting attribute {} of entity {}'.format(highlight(args.attribute), highlight(args.resource)))
in_out.start('Deleting attribute {} of entity {}'.format(highlight(args.attribute), highlight(args.resource)))
response = client.get(api.rest2('sys_md_Attribute'),
params={
'q': 'entity=={};name=={}'.format(args.resource,
Expand All @@ -106,16 +106,16 @@ def _delete_entity_type_attribute(args):


def _delete_package(args):
if args.force or (not args.force and mcmd.io.ask.confirm(
if args.force or (not args.force and mcmd.in_out.ask.confirm(
'Are you sure you want to delete package {} and all of its contents?'.format(args.resource))):
io.start('Deleting package {}'.format(highlight(args.resource)))
in_out.start('Deleting package {}'.format(highlight(args.resource)))
_delete_rows(ResourceType.PACKAGE.get_entity_id(), [args.resource])


def _delete_package_contents(args):
if args.force or (not args.force and mcmd.io.ask.confirm(
if args.force or (not args.force and mcmd.in_out.ask.confirm(
'Are you sure you want to delete the contents of package {}?'.format(args.resource))):
io.start('Deleting contents of package {}'.format(highlight(args.resource)))
in_out.start('Deleting contents of package {}'.format(highlight(args.resource)))
_delete_entity_types_in_package(args.resource)
_delete_packages_in_package(args.resource)

Expand Down Expand Up @@ -143,7 +143,7 @@ def _delete_packages_in_package(package_id):


def _delete_group(args):
if args.force or (not args.force and mcmd.io.ask.confirm(
if args.force or (not args.force and mcmd.in_out.ask.confirm(
'Are you sure you want to delete group {}?'.format(args.resource))):
io.start('Deleting group {}'.format(highlight(args.resource)))
client.delete(urljoin(api.group(), args.resource))
Expand Down
10 changes: 5 additions & 5 deletions mcmd/commands/disable.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from mcmd.commands._registry import arguments
from mcmd.core.command import command
from mcmd.io import ask
from mcmd.io import io
from mcmd.io.io import highlight
from mcmd.in_out import ask
from mcmd.in_out import in_out
from mcmd.in_out.in_out import highlight
from mcmd.molgenis import api
from mcmd.molgenis.client import put
from mcmd.molgenis.resources import ensure_resource_exists, ResourceType
Expand Down Expand Up @@ -48,14 +48,14 @@ def disable_rls(args):
if not ask.confirm('Are you sure you want to disable row level security on %s?' % args.entity):
return

io.start('Disabling row level security on entity type %s' % highlight(args.entity))
in_out.start('Disabling row level security on entity type %s' % highlight(args.entity))

ensure_resource_exists(args.entity, ResourceType.ENTITY_TYPE)
security.disable_row_level_security(args.entity)


@command
def disable_language(args):
io.start('Disabling language {}'.format(highlight(args.language)))
in_out.start('Disabling language {}'.format(highlight(args.language)))
url = api.rest1('sys_Language/{}/active'.format(args.language))
put(url, 'false')
10 changes: 5 additions & 5 deletions mcmd/commands/enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from mcmd.core.command import command
from mcmd.core.compatibility import deprecated
from mcmd.core.errors import McmdError
from mcmd.io import io
from mcmd.io.io import highlight
from mcmd.in_out import in_out
from mcmd.in_out.in_out import highlight
from mcmd.molgenis import api
from mcmd.molgenis.client import post, put
from mcmd.molgenis.resources import one_resource_exists, ensure_resource_exists, ResourceType
Expand Down Expand Up @@ -70,7 +70,7 @@ def add_arguments(subparsers):

@command
def enable_rls(args):
io.start('Enabling row level security on entity type %s' % highlight(args.entity))
in_out.start('Enabling row level security on entity type %s' % highlight(args.entity))

ensure_resource_exists(args.entity, ResourceType.ENTITY_TYPE)
security.enable_row_level_security(args.entity)
Expand All @@ -90,7 +90,7 @@ def enable_theme(args):
:return None
"""
theme = args.theme.replace('.css', '').replace('.min', '')
io.start('Applying theme {}'.format(highlight(theme)))
in_out.start('Applying theme {}'.format(highlight(theme)))
# Resource can be bootstrap-name.min.css (if molgenis theme), or name.min.css (if uploaded .min.css), or
# name.css (if uploaded as .css).
if one_resource_exists([theme + '.min.css', theme + '.css', 'bootstrap-' + theme + '.min.css'], ResourceType.THEME):
Expand All @@ -106,6 +106,6 @@ def enable_theme(args):

@command
def enable_language(args):
io.start('Enabling language {}'.format(highlight(args.language)))
in_out.start('Enabling language {}'.format(highlight(args.language)))
url = api.rest1('sys_Language/{}/active'.format(args.language))
put(url, 'true')
8 changes: 4 additions & 4 deletions mcmd/commands/give.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from mcmd.core.command import command
from mcmd.core.compatibility import version
from mcmd.core.errors import McmdError
from mcmd.io import io
from mcmd.io.io import highlight
from mcmd.in_out import in_out
from mcmd.in_out.in_out import highlight
from mcmd.molgenis.principals import PrincipalType, get_principal_type_from_args
from mcmd.molgenis.resources import detect_resource_type, ensure_resource_exists, ResourceType
from mcmd.molgenis.security import security
Expand Down Expand Up @@ -127,7 +127,7 @@ def _validate_args(args):

def _grant(principal_type: PrincipalType, principal_name: str, resource_type: ResourceType, entity_type_id: str,
permission: Permission):
io.start('Giving %s %s permission to %s on %s %s' % (principal_type.value,
in_out.start('Giving %s %s permission to %s on %s %s' % (principal_type.value,
highlight(principal_name),
highlight(permission.value),
resource_type.get_label().lower(),
Expand All @@ -138,7 +138,7 @@ def _grant(principal_type: PrincipalType, principal_name: str, resource_type: Re

def _grant_rls(principal_type: PrincipalType, principal_name: str, entity_type_id: str,
entity_id: str, permission: Permission):
io.start('Giving %s %s permission to %s on row %s of entity type %s' % (principal_type.value,
in_out.start('Giving %s %s permission to %s on row %s of entity type %s' % (principal_type.value,
highlight(principal_name),
highlight(permission.value),
highlight(entity_id),
Expand Down
12 changes: 6 additions & 6 deletions mcmd/commands/history.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from mcmd.commands._registry import arguments
from mcmd.core import history as hist
from mcmd.core.command import command, CommandType
from mcmd.io import io
from mcmd.io.logging import get_logger
from mcmd.in_out import in_out
from mcmd.in_out.logging import get_logger


# =========
Expand Down Expand Up @@ -38,15 +38,15 @@ def add_arguments(subparsers):
@command
def history(args):
if args.clear:
io.start('Clearing history')
in_out.start('Clearing history')
hist.clear()
else:
lines = hist.read(args.number, include_fails=True)
if len(lines) == 0:
log.info('History is empty.')
for line in lines:
io.start(line[1])
in_out.start(line[1])
if line[0]:
io.succeed()
in_out.succeed()
else:
io.error(None)
in_out.error(None)
Loading

0 comments on commit b352e10

Please sign in to comment.