From 6d6c6f284badd953e462da439e737d6c6baa9911 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Wed, 29 Jul 2015 11:47:56 -0700 Subject: [PATCH] Incorporated Kuba's feedback --- ...tshelp_letsencrypt_apache.py => apache.py} | 24 +++++++++---------- ...sencrypt_apache_test.py => apache_test.py} | 4 ++-- letshelp-letsencrypt/setup.py | 13 +++++++++- 3 files changed, 26 insertions(+), 15 deletions(-) rename letshelp-letsencrypt/letshelp_letsencrypt/{letshelp_letsencrypt_apache.py => apache.py} (95%) rename letshelp-letsencrypt/letshelp_letsencrypt/{letshelp_letsencrypt_apache_test.py => apache_test.py} (98%) diff --git a/letshelp-letsencrypt/letshelp_letsencrypt/letshelp_letsencrypt_apache.py b/letshelp-letsencrypt/letshelp_letsencrypt/apache.py similarity index 95% rename from letshelp-letsencrypt/letshelp_letsencrypt/letshelp_letsencrypt_apache.py rename to letshelp-letsencrypt/letshelp_letsencrypt/apache.py index 94ba979d9..046542641 100755 --- a/letshelp-letsencrypt/letshelp_letsencrypt/letshelp_letsencrypt_apache.py +++ b/letshelp-letsencrypt/letshelp_letsencrypt/apache.py @@ -83,7 +83,7 @@ def copy_config(server_root, temp_dir): :rtype: `tuple` of `list` of `str` """ - copied_files, copied_dirs = list(), list() + copied_files, copied_dirs = [], [] dir_len = len(os.path.dirname(server_root)) for config_path, config_dirs, config_files in os.walk(server_root): @@ -91,7 +91,7 @@ def copy_config(server_root, temp_dir): os.mkdir(temp_path) copied_all = True - copied_files_in_current_dir = list() + copied_files_in_current_dir = [] for config_file in config_files: config_file_path = os.path.join(config_path, config_file) temp_file_path = os.path.join(temp_path, config_file) @@ -202,15 +202,15 @@ def verify_config(args): :param argparse.Namespace args: Parsed command line arguments """ - try: - with open(os.devnull, "w") as devnull: + with open(os.devnull, "w") as devnull: + try: subprocess.check_call([args.apache_ctl, "-d", args.server_root, "-f", args.config_file, "-t"], stdout=devnull, stderr=subprocess.STDOUT) - except OSError: - sys.exit(_NO_APACHECTL) - except subprocess.CalledProcessError: - sys.exit("Syntax check from apachectl failed") + except OSError: + sys.exit(_NO_APACHECTL) + except subprocess.CalledProcessError: + sys.exit("Syntax check from apachectl failed") def locate_config(apache_ctl): @@ -234,9 +234,9 @@ def locate_config(apache_ctl): for line in output.splitlines(): # Relevant output lines are of the form: -D DIRECTIVE="VALUE" if "HTTPD_ROOT" in line: - server_root = line[line.find("\"")+1:-1] + server_root = line[line.find('"')+1:-1] elif "SERVER_CONFIG_FILE" in line: - config_file = line[line.find("\"")+1:-1] + config_file = line[line.find('"')+1:-1] if not (server_root and config_file): sys.exit("Unable to locate Apache configuration. Please run this " @@ -283,7 +283,7 @@ def get_args(): def main(): """Main script execution""" args = get_args() - if not args.server_root: + if args.server_root is None: args.server_root, args.config_file = locate_config(args.apache_ctl) verify_config(args) @@ -296,7 +296,7 @@ def main(): with contextlib.closing(tarfile.open(tarpath, mode="w:gz")) as tar: tar.add(tempdir, arcname=".") - # Submit tarpath + # TODO: Submit tarpath if __name__ == "__main__": diff --git a/letshelp-letsencrypt/letshelp_letsencrypt/letshelp_letsencrypt_apache_test.py b/letshelp-letsencrypt/letshelp_letsencrypt/apache_test.py similarity index 98% rename from letshelp-letsencrypt/letshelp_letsencrypt/letshelp_letsencrypt_apache_test.py rename to letshelp-letsencrypt/letshelp_letsencrypt/apache_test.py index c514118fb..e1012797a 100644 --- a/letshelp-letsencrypt/letshelp_letsencrypt/letshelp_letsencrypt_apache_test.py +++ b/letshelp-letsencrypt/letshelp_letsencrypt/apache_test.py @@ -10,7 +10,7 @@ import unittest import mock -import letshelp_letsencrypt.letshelp_letsencrypt_apache as letshelp_le_apache +import letshelp_letsencrypt.apache as letshelp_le_apache _PARTIAL_CONF_PATH = os.path.join("mods-available", "ssl.load") @@ -25,7 +25,7 @@ _SECRET_FILE = pkg_resources.resource_filename( __name__, os.path.join("testdata", "super_secret_file.txt")) -_MODULE_NAME = "letshelp_letsencrypt.letshelp_letsencrypt_apache" +_MODULE_NAME = "letshelp_letsencrypt.apache" _COMPILE_SETTINGS = """Server version: Apache/2.4.10 (Debian) diff --git a/letshelp-letsencrypt/setup.py b/letshelp-letsencrypt/setup.py index 58b28bc7e..95c3e5c74 100644 --- a/letshelp-letsencrypt/setup.py +++ b/letshelp-letsencrypt/setup.py @@ -1,11 +1,22 @@ +import sys + from setuptools import setup from setuptools import find_packages -install_requires = ["mock<1.1.0",] +install_requires = [] +if sys.version_info < (2, 7): + install_requires.append("mock<1.1.0") +else: + install_requires.append("mock") setup( name="letshelp-letsencrypt", packages=find_packages(), install_requires=install_requires, + entry_points={ + 'console_scripts': [ + "letshelp-letsencrypt-apache = letshelp_letsencrypt.apache:main", + ], + }, )