File size: 33,300 Bytes
5980447 |
1 2 |
{"repo": "grahame/sedge", "pull_number": 7, "instance_id": "grahame__sedge-7", "issue_numbers": "", "base_commit": "3f3ca088d395257845d9f316d59e0f778fce7ada", "patch": "diff --git a/sedge/cli.py b/sedge/cli.py\n--- a/sedge/cli.py\n+++ b/sedge/cli.py\n@@ -1,147 +1,191 @@\n-import argparse\n import difflib\n import os.path\n import sys\n+from pathlib import Path\n from tempfile import NamedTemporaryFile\n-from .engine import SedgeEngine, SedgeException, ConfigOutput\n+\n+import click\n+\n+from .engine import SedgeEngine, ConfigOutput\n from .keylib import KeyLibrary\n+from .templates import sedge_config_header\n+\n+\n+def get_file_backup_name(file_name):\n+ return file_name + '.pre_sedge'\n \n \n-def ask_overwrite(fname):\n- print(\n- \"WARNING: `%s' already exists and was not generated by sedge.\" % fname,\n- file=sys.stderr)\n- confirm = input(\"Enter `yes' to overwite: \")\n+def ask_overwrite(file_name):\n+ click.echo(\"WARNING: '{}' already exists and was not generated by sedge.\".format(file_name), err=True)\n+ confirm = input(\"Enter 'yes' to overwrite (I'll make a backup called '{backup_file}'): \".format(\n+ backup_file=get_file_backup_name(file_name))\n+ )\n return confirm == 'yes'\n \n \n-def check_or_confirm_overwrite(fname):\n- \"returns True if OK to proceed, False otherwise\"\n+def backup_file(file_name):\n+ _backup_file = get_file_backup_name(file_name)\n+ os.rename(file_name, _backup_file)\n+ click.echo('Your previous SSH configuration file has been renamed to: {}'.format(_backup_file), err=True)\n+\n+\n+def check_or_confirm_overwrite(file_name):\n+ \"\"\"\n+ Returns True if OK to proceed, False otherwise\n+ \"\"\"\n try:\n- with open(fname) as fd:\n+ with open(file_name) as fd:\n header = next(fd)\n if header.find(':sedge:') == -1:\n- okay = ask_overwrite(fname)\n+ okay = ask_overwrite(file_name)\n if okay:\n- backup_file = fname + '.pre-sedge'\n- os.rename(fname, backup_file)\n- print(\"your previous SSH configuration file has been renamed to:\\n%s\" % (backup_file), file=sys.stderr)\n- except OSError:\n- pass\n- except StopIteration:\n- pass\n- return True\n+ backup_file(file_name)\n+ else:\n+ return False\n+\n+ except FileNotFoundError:\n+ click.echo(\"{} not found\".format(file_name), err=True)\n+ except StopIteration as e:\n+ click.echo(repr(e), err=True)\n+ else:\n+ return True\n \n \n def diff_config_changes(before, after):\n def get_data(f):\n- with open(f) as fd:\n- return fd.read().splitlines(True)\n+ try:\n+ with open(f) as fd:\n+ return fd.read().splitlines(True)\n+ except FileNotFoundError:\n+ click.echo(\"{} not found\".format(f), err=True)\n+ return []\n+\n a = get_data(before)\n b = get_data(after)\n diff_lines = list(difflib.unified_diff(a, b))\n if not diff_lines:\n- print(\"no changes.\", file=sys.stderr)\n+ click.echo('no changes.', err=True)\n else:\n- print('configuration changes:', file=sys.stderr)\n- print(''.join(diff_lines), file=sys.stderr)\n+ click.echo('configuration changes:', err=True)\n+ click.echo(''.join(diff_lines), err=True)\n \n \n-def command_list_keys(args):\n- library = KeyLibrary(args.key_directory)\n- library.list_keys()\n+class SedgeConfig:\n+ def __init__(self):\n+ pass\n \n \n-def command_add_keys(args):\n- library = KeyLibrary(args.key_directory)\n- library.add_keys()\n+sedge_config = click.make_pass_decorator(SedgeConfig, ensure=True)\n+\n+\n+@click.group()\n+@click.version_option()\n+@click.option('-c',\n+ '--config-file',\n+ default=os.path.expanduser('~/.sedge/config'), )\n+@click.option('-o',\n+ '--output-file',\n+ default=os.path.expanduser('~/.ssh/config'), )\n+@click.option('-n',\n+ '--no-verify',\n+ is_flag=True,\n+ help='do not verify HTTPS requests')\n+@click.option('-k',\n+ '--key-directory',\n+ default=os.path.expanduser('~/.ssh'),\n+ help='directory to scan for SSH keys', )\n+@click.option('-v', '--verbose', count=True, default=0)\n+@sedge_config\n+def cli(config, verbose, key_directory, no_verify, output_file, config_file):\n+ \"\"\"\n+ Template and share OpenSSH ssh_config(5) files. A preprocessor for\n+ OpenSSH configurations.\n+ \"\"\"\n+ config.verbose = verbose\n+ config.key_directory = key_directory\n+ config.config_file = config_file\n+ config.output_file = output_file\n+ config.no_verify = no_verify\n+\n+\n+@cli.command('init')\n+@sedge_config\n+def init(config):\n+ \"\"\"\n+ Initialise ~./sedge/config file if none exists.\n+ Good for first time sedge usage\n+ \"\"\"\n+ from pkg_resources import resource_stream\n+ import shutil\n+\n+ config_file = Path(config.config_file)\n+ if config_file.is_file():\n+ click.echo('{} already exists, maybe you want $ sedge update'.format(config_file))\n+ sys.exit()\n+\n+ config_file.parent.mkdir(parents=True, exist_ok=True)\n+ with resource_stream(__name__, 'sedge_template.conf') as src_stream:\n+ with open(config.config_file, 'wb') as target_stream:\n+ shutil.copyfileobj(src_stream, target_stream)\n+\n+\n+@cli.command('update')\n+@sedge_config\n+def update(config):\n+ \"\"\"\n+ Update ssh config from sedge specification\n+ \"\"\"\n \n-\n-def command_update(args):\n def write_to(out):\n- config.output(out)\n- library = KeyLibrary(args.key_directory)\n- with open(args.config_file) as fd:\n- config = SedgeEngine(library, fd, not args.no_verify, url=args.config_file)\n- if args.output_file == '-':\n+ engine.output(out)\n+\n+ config_file = Path(config.config_file)\n+ if not config_file.is_file():\n+ click.echo('No file {} '.format(config_file), err=True)\n+ sys.exit()\n+\n+ library = KeyLibrary(config.key_directory)\n+ with config_file.open() as fd:\n+ engine = SedgeEngine(library, fd, not config.no_verify, url=config.config_file)\n+\n+ if config.output_file == '-':\n write_to(ConfigOutput(sys.stdout))\n return\n- if not check_or_confirm_overwrite(args.output_file):\n- print(\"Aborting.\", file=sys.stderr)\n+\n+ if not check_or_confirm_overwrite(config.output_file):\n+ click.echo('Aborting.', err=True)\n sys.exit(1)\n \n- tmpf = NamedTemporaryFile(mode='w', dir=os.path.dirname(args.output_file), delete=False)\n+ tmp_file = NamedTemporaryFile(mode='w', dir=os.path.dirname(config.output_file), delete=False)\n try:\n- tmpf.file.write('''\\\n-# :sedge:\n-#\n-# this configuration generated from `sedge' file:\n-# %s\n-#\n-# do not edit this file manually, edit the source file and re-run `sedge'\n-#\n-\n-''' % (args.config_file))\n- write_to(ConfigOutput(tmpf.file))\n- tmpf.close()\n- if args.verbose:\n- diff_config_changes(args.output_file, tmpf.name)\n- os.rename(tmpf.name, args.output_file)\n+ tmp_file.file.write(sedge_config_header.format(config.config_file))\n+ write_to(ConfigOutput(tmp_file.file))\n+ tmp_file.close()\n+ if config.verbose:\n+ diff_config_changes(config.output_file, tmp_file.name)\n+ os.rename(tmp_file.name, config.output_file)\n except:\n- os.unlink(tmpf.name)\n+ os.unlink(tmp_file.name)\n raise\n \n \n-def main():\n- commands = {\n- 'update': command_update,\n- 'list-keys': command_list_keys,\n- 'add-keys': command_add_keys,\n- }\n- parser = argparse.ArgumentParser()\n- parser.add_argument(\n- '-k', '--key_directory',\n- default=os.path.expanduser('~/.ssh'),\n- type=str,\n- help='directory to scan for SSH keys')\n- parser.add_argument(\n- '-v', '--verbose',\n- action='store_true',\n- help='verbose output')\n- parser.add_argument(\n- '--version', action='store_true',\n- help='print version and exit')\n- parser.add_argument(\n- '-c', '--config-file',\n- default=os.path.expanduser('~/.sedge/config'),\n- nargs='?')\n- parser.add_argument(\n- '-o', '--output-file',\n- default=os.path.expanduser('~/.ssh/config'),\n- nargs='?')\n- parser.add_argument(\n- '-n', '--no-verify',\n- action='store_true',\n- help='do not verify HTTPS requests')\n- parser.add_argument(\n- 'command',\n- help='action to take',\n- nargs='?',\n- default='update',\n- choices=commands.keys())\n- args = parser.parse_args()\n- if args.version:\n- import pkg_resources\n- version = pkg_resources.require(\"sedge\")[0].version\n- print('''\\\n-sedge, version %s\n-\n-Copyright \u00a9 2015 Grahame Bowland\n-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n-This is free software: you are free to change and redistribute it.\n-There is NO WARRANTY, to the extent permitted by law.''' % (version))\n- sys.exit(0)\n- try:\n- commands[args.command](args)\n- except SedgeException as e:\n- print('Error: %s' % (e), file=sys.stderr)\n+@cli.group()\n+@sedge_config\n+def keys(config):\n+ \"\"\"\n+ Manage ssh keys\n+ \"\"\"\n+\n+\n+@keys.command('list')\n+@sedge_config\n+def command_list_keys(config):\n+ library = KeyLibrary(path=config.key_directory, verbose=config.verbose)\n+ library.list_keys()\n+\n+\n+@keys.command('add')\n+@sedge_config\n+def command_add_keys(config):\n+ library = KeyLibrary(path=config.key_directory, verbose=config.verbose)\n+ library.add_keys()\ndiff --git a/sedge/engine.py b/sedge/engine.py\n--- a/sedge/engine.py\n+++ b/sedge/engine.py\n@@ -1,10 +1,12 @@\n-import requests\n-import urllib\n+import os\n import pipes\n import sys\n-import os\n-from itertools import product\n+import urllib\n from io import StringIO\n+from itertools import product\n+\n+import requests\n+\n from .keylib import KeyNotFound\n \n \n@@ -64,7 +66,7 @@ def get_lines(self, config_access, visited_set):\n return lines\n \n def __repr__(self):\n- s = \"%s:%s\" % (type(self).__name__, self.name)\n+ s = \"{_type}:{name}\".format(_type=type(self).__name__, name=self.name)\n if self.with_exprs:\n s += '[' + ','.join(' '.join(t) for t in self.with_exprs) + ']'\n return '<%s>' % s\n@@ -126,8 +128,7 @@ def expand_with_token(cls, s):\n from_width = len('%0s' % range_parts[0])\n to_width = len('%0s' % range_parts[1])\n except ValueError:\n- raise ParserException(\n- 'expected an integer in range definition.')\n+ raise ParserException('expected an integer in range definition.')\n if from_width == to_width:\n return [\"%0*d\" % (to_width, t) for t in range(from_val, to_val, incr)]\n else:\n@@ -188,6 +189,7 @@ class SectionConfigAccess:\n sections may require access to other parts of the file.\n this class provides that access.\n \"\"\"\n+\n def __init__(self, config):\n self._config = config\n \n@@ -198,14 +200,17 @@ def get_keyfile(self, name):\n try:\n fingerprints = self._config.keydefs[name]\n except KeyError:\n- self._config.warn(\"identity '%s' is not defined (missing @key definition)\" % name)\n+ self._config.warn(\"identity '{}' is not defined (missing @key definition)\".format(name))\n return None\n for fingerprint in fingerprints:\n try:\n return self._config._key_library.lookup(fingerprint)\n except KeyNotFound:\n pass\n- self._config.warn(\"identity '%s' (fingerprints %s) not found in SSH key library\" % (name, '; '.join(fingerprints)))\n+ self._config.warn(\"identity '{name}' (fingerprints {fingerprints}) not found in SSH key library\".format(\n+ name=name,\n+ fingerprints='; '.join(fingerprints))\n+ )\n \n def get_variables(self):\n return self._config.sections[0].get_variables()\n@@ -228,6 +233,7 @@ def write_stanza(self, it):\n def to_line(cls, keyword, parts, indent=0):\n def add_indent(s):\n return ' ' * indent + s\n+\n if len(parts) == 1:\n return add_indent(' '.join([keyword, '=', parts[0]]))\n out = [keyword]\n@@ -235,7 +241,7 @@ def add_indent(s):\n if '\"' in part:\n raise OutputException(\"quotation marks may not be used in arguments\")\n if ' ' in part:\n- out.append('\"%s\"' % part)\n+ out.append(\"{}\".format(part))\n else:\n out.append(part)\n return add_indent(' '.join(out))\n@@ -246,6 +252,7 @@ class SedgeEngine:\n base parser for a sedge configuration file.\n handles all directives and expansions\n \"\"\"\n+\n def __init__(self, key_library, fd, verify_ssl, url=None, args=None, parent_keydefs=None, via_include=False):\n self._key_library = key_library\n self._url = url\n@@ -259,8 +266,8 @@ def __init__(self, key_library, fd, verify_ssl, url=None, args=None, parent_keyd\n self.keydefs.update(parent_keydefs)\n self.parse(fd)\n \n- def warn(self, mesg):\n- print(\"%s: %s\" % (self._url, mesg), file=sys.stderr)\n+ def warn(self, message):\n+ print(\"{url}: {msg}\".format(url=self._url, msg=message), file=sys.stderr)\n \n @classmethod\n def parse_other_space(cls, other):\n@@ -273,6 +280,7 @@ def pop_current():\n if val:\n args.append(val)\n current.clear()\n+\n for c in other:\n if in_quote:\n if c == '\"':\n@@ -295,15 +303,15 @@ def pop_current():\n pop_current()\n return args\n \n+ # from the ssh_config manual page:\n+ # > ... format ``keyword arguments''. Configuration options may be\n+ # > separated by whitespace or optional whitespace and exactly one `='; the\n+ # > latter format is useful to avoid the need to quote whitespace when speci-\n+ # > fying configuration options using the ssh, scp, and sftp -o option.\n+ # > Arguments may optionally be enclosed in double quotes (\") in order to\n+ # > represent arguments containing spaces.\n @classmethod\n def parse_config_line(cls, line):\n- # from the ssh_config manual page:\n- # > ... format ``keyword arguments''. Configuration options may be\n- # > separated by whitespace or optional whitespace and exactly one `='; the\n- # > latter format is useful to avoid the need to quote whitespace when speci-\n- # > fying configuration options using the ssh, scp, and sftp -o option.\n- # > Arguments may optionally be enclosed in double quotes (\") in order to\n- # > represent arguments containing spaces.\n if '=' in line:\n line_parts = line.strip().split('=', 1)\n return line_parts[0].rstrip(), [line_parts[1].lstrip()]\n@@ -318,7 +326,7 @@ def is_include(self):\n return self._via_include\n \n def parse(self, fd):\n- \"very simple parser - but why would we want it to be complex?\"\n+ \"\"\"very simple parser - but why would we want it to be complex?\"\"\"\n \n def resolve_args(args):\n # FIXME break this out, it's in common with the templating stuff elsewhere\n@@ -334,18 +342,15 @@ def resolve_args(args):\n def handle_section_defn(keyword, parts):\n if keyword == '@HostAttrs':\n if len(parts) != 1:\n- raise ParserException(\n- 'usage: @HostAttrs <hostname>')\n+ raise ParserException('usage: @HostAttrs <hostname>')\n if self.sections[0].has_pending_with():\n- raise ParserException(\n- '@with not supported with @HostAttrs')\n+ raise ParserException('@with not supported with @HostAttrs')\n self.sections.append(HostAttrs(parts[0]))\n return True\n if keyword == 'Host':\n if len(parts) != 1:\n raise ParserException('usage: Host <hostname>')\n- self.sections.append(\n- Host(parts[0], self.sections[0].pop_pending_with()))\n+ self.sections.append(Host(parts[0], self.sections[0].pop_pending_with()))\n return True\n \n def handle_vardef(root, keyword, parts):\n@@ -353,18 +358,21 @@ def handle_vardef(root, keyword, parts):\n root.add_pending_with(parts)\n return True\n \n- def handle_set_args(section, parts):\n+ def handle_set_args(_, parts):\n if len(parts) == 0:\n raise ParserException('usage: @args arg-name ...')\n if not self.is_include():\n return\n if self._args is None or len(self._args) != len(parts):\n- raise ParserException('required arguments not passed to include %s (%s)' % (self._url, ', '.join(parts)))\n+ raise ParserException('required arguments not passed to include {url} ({parts})'.format(\n+ url=self._url,\n+ parts=', '.join(parts))\n+ )\n root = self.sections[0]\n for key, value in zip(parts, self._args):\n root.set_value(key, value)\n \n- def handle_set_value(section, parts):\n+ def handle_set_value(_, parts):\n if len(parts) != 2:\n raise ParserException('usage: @set <key> <value>')\n root = self.sections[0]\n@@ -380,15 +388,15 @@ def handle_via(section, parts):\n raise ParserException('usage: @via <Hostname>')\n section.add_line(\n 'ProxyCommand',\n- ('ssh %s nc %%h %%p 2> /dev/null' %\n- (pipes.quote(resolve_args(parts)[0])),))\n+ ('ssh {args} nc %h %p 2> /dev/null'.format(args=pipes.quote(resolve_args(parts)[0])), )\n+ )\n \n def handle_identity(section, parts):\n if len(parts) != 1:\n raise ParserException('usage: @identity <name>')\n section.add_identity(resolve_args(parts)[0])\n \n- def handle_include(section, parts):\n+ def handle_include(_, parts):\n if len(parts) == 0:\n raise ParserException('usage: @include <https://...|/path/to/file.sedge> [arg ...]')\n url = parts[0]\n@@ -405,6 +413,7 @@ def handle_include(section, parts):\n text = fd.read()\n else:\n raise SecurityException('error: @includes may only use paths or https:// or file:// URLs')\n+\n subconfig = SedgeEngine(\n self._key_library,\n StringIO(text),\n@@ -415,7 +424,7 @@ def handle_include(section, parts):\n via_include=True)\n self.includes.append((url, subconfig))\n \n- def handle_keydef(section, parts):\n+ def handle_keydef(_, parts):\n if len(parts) < 2:\n raise ParserException('usage: @key <name> [fingerprint]...')\n name = parts[0]\n@@ -448,8 +457,7 @@ def handle_keyword(section, keyword, parts):\n if handle_keyword(current_section, keyword, parts):\n continue\n if keyword.startswith('@'):\n- raise ParserException(\n- \"unknown expansion keyword '%s'\" % (keyword))\n+ raise ParserException(\"unknown expansion keyword {}\".format(keyword))\n # use other rather than parts to avoid messing up user\n # whitespace; we don't handle quotes in here as we don't\n # need to\n@@ -461,10 +469,9 @@ def sections_for_cls(self, cls):\n def _get_section_by_name(self, name):\n matches = [t for t in self.sections if t.name == name]\n if len(matches) > 1:\n- raise ParserException(\n- \"More than one section with name '%s'\" % (name))\n+ raise ParserException(\"More than one section with name '{}'\".format(name))\n if len(matches) == 0:\n- raise ParserException(\"No such section: %s\" % (name))\n+ raise ParserException(\"No such section: {}\".format(name))\n return matches[0]\n \n def host_stanzas(self):\n@@ -477,7 +484,7 @@ def output(self, out, stanza_names=None):\n root = self.sections[0]\n if self.is_include():\n if root.has_lines():\n- print(\"Warning: global config in @include '%s' ignored.\" % (self._url), file=sys.stderr)\n+ print(\"Warning: global config in @include '{url}' ignored.\".format(url=self._url), file=sys.stderr)\n print(\"Ignored lines are:\", file=sys.stderr)\n warning_fd = StringIO()\n warning_out = ConfigOutput(warning_fd)\n@@ -496,7 +503,7 @@ def output(self, out, stanza_names=None):\n stanza_names.add(hostname)\n out.write_stanza(stanza)\n if dupes:\n- print(\"Warning: duplicated hosts parsing '%s'\" % (self._url), file=sys.stderr)\n+ print(\"Warning: duplicated hosts parsing '{url}'\".format(url=self._url), file=sys.stderr)\n print(\" %s\" % (', '.join(sorted(dupes))), file=sys.stderr)\n \n for url, subconfig in self.includes:\ndiff --git a/sedge/keylib.py b/sedge/keylib.py\n--- a/sedge/keylib.py\n+++ b/sedge/keylib.py\n@@ -1,6 +1,6 @@\n+import os\n import subprocess\n import sys\n-import os\n \n \n class KeyNotFound(Exception):\n@@ -13,6 +13,7 @@ class FingerprintDoesNotParse(Exception):\n \n class KeyLibrary:\n def __init__(self, path, verbose=False):\n+\n self._path = path\n self._verbose = verbose\n self.keys_by_fingerprint = {}\n@@ -22,8 +23,8 @@ def _generate_public_key(self, fname):\n pkey_fname = fname + '.pub'\n if os.access(pkey_fname, os.R_OK):\n return\n- print(\"public key does not exist for private key '%s'\" % fname, file=sys.stderr)\n- print(\"attemping to generate; you may be prompted for a passphrase.\", file=sys.stderr)\n+ print(\"public key does not exist for private key '{name}'\".format(name=fname), file=sys.stderr)\n+ print(\"attempting to generate; you may be prompted for a pass phrase.\", file=sys.stderr)\n try:\n public_key = subprocess.check_output(['ssh-keygen', '-y', '-f', fname])\n except subprocess.CalledProcessError:\n@@ -38,7 +39,6 @@ def _fingerprint_from_keyinfo(cls, output):\n parts = [s for s in (t.strip() for t in output.split(' ')) if s]\n if len(parts) != 4:\n raise FingerprintDoesNotParse()\n- raise\n return parts[1]\n \n def _scan_key(self, fname, recurse=False):\n@@ -56,7 +56,8 @@ def _scan_key(self, fname, recurse=False):\n def _scan(self):\n def rp(path):\n return os.path.relpath(path, self._path)\n- skip = set(('config', 'known_hosts', 'known_hosts.old', 'authorized_keys'))\n+\n+ skip = {'config', 'known_hosts', 'known_hosts.old', 'authorized_keys'}\n for dirpath, dirnames, fnames in os.walk(self._path):\n for name, path in ((t, os.path.join(dirpath, t)) for t in fnames):\n if name.startswith('.'):\n@@ -68,9 +69,16 @@ def rp(path):\n fingerprint = self._scan_key(path)\n if fingerprint is not None:\n if self._verbose:\n- print(\"scanned key '%s' fingerprint '%s'\" % (rp(path, self._path), fingerprint))\n+ print(\"scanned key '{key}' fingerprint '{fingerprint}'\".format(\n+ key=rp(path),\n+ fingerprint=fingerprint)\n+ )\n if fingerprint in self.keys_by_fingerprint:\n- print(\"warning: key '%s' has same fingerprint as '%s', ignoring duplicate key.\" % (rp(self.keys_by_fingerprint[fingerprint]), rp(path)))\n+ print(\n+ \"warning: key '{key}' has same fingerprint as '{otherkey}', ignoring duplicate key.\".format(\n+ key=rp(self.keys_by_fingerprint[fingerprint]),\n+ otherkey=rp(path))\n+ )\n else:\n self.keys_by_fingerprint[fingerprint] = path\n \ndiff --git a/sedge/templates.py b/sedge/templates.py\nnew file mode 100644\n--- /dev/null\n+++ b/sedge/templates.py\n@@ -0,0 +1,11 @@\n+sedge_config_header = \"\"\"\n+# :sedge:\n+#\n+# this configuration generated from `sedge' file:\n+# {}\n+#\n+# do not edit this file manually, edit the source file and re-run `sedge'\n+#\n+\n+\"\"\"\n+\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -1,26 +1,45 @@\n from setuptools import setup, find_packages\n \n-dev_requires = ['flake8', 'nose']\n-install_requires = ['requests>=2.2']\n+dev_requires = [\n+ 'flake8',\n+ 'pytest',\n+ 'tox'\n+]\n+\n+install_requires = [\n+ 'requests',\n+ 'click'\n+]\n+\n+long_description = \"\"\"\n+Template and share OpenSSH ssh_config(5) files.\n+A preprocessor for OpenSSH configurations.\n+Named for the favourite food of the Western Ground Parrot.\n+If you find this software useful, please consider donating to the effort to save this critically endangered species.\n+\n+http://www.western-ground-parrot.org.au/\n+\"\"\"\n \n setup(\n- author = \"Grahame Bowland\",\n- author_email = \"grahame@angrygoats.net\",\n- description = \"Template and share OpenSSH ssh_config files.\",\n- long_description = \"Template and share OpenSSH ssh_config(5) files. A preprocessor for OpenSSH configurations.\\n\\nNamed for the favourite food of the Western Ground Parrot. If you find this software useful, please consider donating to the effort to save this critically endangered species.\",\n- license = \"GPL3\",\n- keywords = \"openssh ssh\",\n- url = \"https://github.com/grahame/sedge\",\n- name = \"sedge\",\n- version = \"1.5.1\",\n- packages = find_packages(exclude=[\"*.tests\", \"*.tests.*\", \"tests.*\", \"tests\"]),\n- extras_require = {\n+ author=\"Grahame Bowland\",\n+ author_email=\"grahame@angrygoats.net\",\n+ description=\"Template and share OpenSSH ssh_config files.\",\n+ long_description=long_description,\n+ license=\"GPL3\",\n+ keywords=\"openssh ssh\",\n+ url=\"https://github.com/grahame/sedge\",\n+ name=\"sedge\",\n+ version=\"2.0\",\n+ packages=find_packages(exclude=[\"*.tests\", \"*.tests.*\", \"tests.*\", \"tests\"]),\n+ extras_require={\n 'dev': dev_requires\n },\n- install_requires = install_requires,\n- entry_points = {\n+ install_requires=install_requires,\n+ entry_points={\n 'console_scripts': [\n- 'sedge = sedge.cli:main',\n+ 'sedge = sedge.cli:cli',\n ],\n- }\n+ },\n+ package_data={'sedge': ['sedge_template.conf']},\n+ include_package_data=True,\n )\n", "test_patch": "diff --git a/sedge/tests.py b/tests/test_sedge.py\nsimilarity index 80%\nrename from sedge/tests.py\nrename to tests/test_sedge.py\n--- a/sedge/tests.py\n+++ b/tests/test_sedge.py\n@@ -1,8 +1,13 @@\n import os\n+import pytest\n from io import StringIO\n-from .engine import SedgeEngine, Host, ConfigOutput, ParserException, OutputException, SecurityException\n-from .keylib import KeyLibrary\n-from nose.tools import eq_, raises\n+\n+from sedge.engine import (\n+ SedgeEngine, Host, ConfigOutput,\n+ ParserException, OutputException, SecurityException\n+)\n+\n+from sedge.keylib import KeyLibrary\n \n \n def config_for_text(in_text):\n@@ -16,7 +21,7 @@ def check_parse_result(in_text, expected_text):\n fd = StringIO()\n out = ConfigOutput(fd)\n config.output(out)\n- eq_(expected_text, fd.getvalue())\n+ assert expected_text == fd.getvalue()\n \n \n def test_empty_file():\n@@ -117,7 +122,7 @@ def test_include_args():\n \n def check_fingerprint(data, fingerprint):\n determined = KeyLibrary._fingerprint_from_keyinfo(data)\n- eq_(determined, fingerprint)\n+ assert determined == fingerprint\n \n \n def test_fingerprint_parser():\n@@ -134,7 +139,7 @@ def test_fingerprint_parser_double_space():\n \n def check_config_parser(s, expected):\n result = SedgeEngine.parse_config_line(s)\n- eq_(result, expected)\n+ assert result == expected\n \n \n def test_parser_noarg():\n@@ -219,7 +224,7 @@ def test_parser_equals_allthespc():\n \n def check_to_line(keyword, parts, expected, **kwargs):\n result = ConfigOutput.to_line(keyword, parts, **kwargs)\n- eq_(result, expected)\n+ assert result == expected\n \n \n def test_to_line_no_args():\n@@ -239,73 +244,75 @@ def test_to_line_two_args():\n \n \n def test_to_line_two_args_spaces():\n- check_to_line('Test', ['Arg1 is Spacey', 'Arg2 is also Spacey'], 'Test \"Arg1 is Spacey\" \"Arg2 is also Spacey\"')\n+ check_to_line('Test', ['Arg1 is Spacey', 'Arg2 is also Spacey'], 'Test Arg1 is Spacey Arg2 is also Spacey')\n \n \n-@raises(OutputException)\n def test_to_line_two_args_spaces_quotes():\n- ConfigOutput.to_line('Test', ['This has a quote\"', 'Eep'])\n+ with pytest.raises(OutputException) as e_info:\n+ ConfigOutput.to_line('Test', ['This has a quote\"', 'Eep'])\n \n \n-@raises(ParserException)\n def test_root_is_fails():\n- config_for_text('@is a-thing')\n+ with pytest.raises(ParserException) as e_info:\n+ config_for_text('@is a-thing')\n \n \n-@raises(ParserException)\n def test_invalid_range_fails():\n- Host.expand_with(['{1}'])\n+ with pytest.raises(ParserException) as e_info:\n+ Host.expand_with(['{1}'])\n \n \n-@raises(ParserException)\n def test_invalid_range_dup_fails():\n- Host.expand_with(['{1..2..4}'])\n+ with pytest.raises(ParserException) as e_info:\n+ Host.expand_with(['{1..2..4}'])\n \n \n-@raises(ParserException)\n def test_invalid_padded_range_dup_fails():\n- Host.expand_with(['{001..002..004}'])\n+ with pytest.raises(ParserException) as e_info:\n+ Host.expand_with(['{001..002..004}'])\n \n \n-@raises(ParserException)\n def test_invalid_range_nonint_fails():\n- Host.expand_with(['{1..cat}'])\n+ with pytest.raises(ParserException) as e_info:\n+ Host.expand_with(['{1..cat}'])\n \n \n-@raises(ParserException)\n def test_invalid_padded_range_nonint_fails():\n- Host.expand_with(['{001..cat}'])\n+ with pytest.raises(ParserException) as e_info:\n+ Host.expand_with(['{001..cat}'])\n \n \n-@raises(ParserException)\n def test_invalid_range_empty():\n- Host.expand_with(['{}'])\n+ with pytest.raises(ParserException) as e_info:\n+ Host.expand_with(['{}'])\n \n \n def test_expand():\n- eq_(['1', '2', '3'], Host.expand_with(['{1..3}']))\n+ assert ['1', '2', '3'] == Host.expand_with(['{1..3}'])\n \n \n def test_padded_expand():\n- eq_(['001', '002', '003'], Host.expand_with(['{001..003}']))\n+ assert ['001', '002', '003'] == Host.expand_with(['{001..003}'])\n \n \n def test_expand_range():\n- eq_(['1', '3'], Host.expand_with(['{1..3/2}']))\n+ assert ['1', '3'] == Host.expand_with(['{1..3/2}'])\n \n \n def test_padded_expand_range():\n- eq_(['001', '003'], Host.expand_with(['{001..003/2}']))\n+ assert ['001', '003'] == Host.expand_with(['{001..003/2}'])\n \n \n-@raises(SecurityException)\n def test_http_disallowed():\n- config_for_text(\"@include http://example.com/thing.sedge\")\n+ with pytest.raises(SecurityException) as e_info:\n+ config_for_text(\"@include http://example.com/thing.sedge\")\n \n \n def test_subst():\n- check_parse_result('@set goat cheese\\n@set username percy\\nHost <goat>\\nUsername <username>', 'Host = cheese\\n Username = percy\\n')\n+ check_parse_result('@set goat cheese\\n@set username percy\\nHost <goat>\\nUsername <username>',\n+ 'Host = cheese\\n Username = percy\\n')\n \n \n def test_subst_with_via():\n- check_parse_result('@set goat cheese\\n\\nHost test\\n@via <goat>', 'Host = test\\n ProxyCommand = ssh cheese nc %h %p 2> /dev/null\\n')\n+ check_parse_result('@set goat cheese\\n\\nHost test\\n@via <goat>',\n+ 'Host = test\\n ProxyCommand = ssh cheese nc %h %p 2> /dev/null\\n')\n", "problem_statement": "", "hints_text": "", "created_at": "2017-03-27T13:37:09Z"}
|