From 7e442546206bfa2f9d2421d8701b790bc9dfc6d5 Mon Sep 17 00:00:00 2001 From: Daniel Jilg Date: Thu, 1 Jun 2017 11:45:21 +0200 Subject: [PATCH] 1.1 (#26) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed a bug when running in Python 2.x * Fixed a bug that occurred when no tags were present * Removed Django and dependencies from internal requirements.txt Please make sure to have all your dependencies, including Django, in your project’s requirements.txt instead * Fixed a bug where debug mode would halt execution * Fixed an issue where the image would be built multiple times during deploy * Cleaned up line breaks * Moved support files to their own directory * Added Initialize command * Added code to deal with existing files in Py3 and Py2 * Added hint to edit deploy.ini * Fixed a bug with Python2.7 compatbility * Improved handling of config files * Changed build process to show failed builds. * Changed build process to show failed builds. * Added initialize command that creates a new jonah project * Fixed a Python3 compatibility issue * Fixed another Python3 issue * Added a dash of documentaiton to system_initialization.sh * Renamed deploy.py to jonah.py Things are getting serious and professional over here :D~ * Moved .dockerignore to the correct directory * Created a preliminary python package * Switched README to reStructured Text for better PyPI compatibility * Adding supervisord conf file, which I forgot * Progress re Docs * Readme contd: Moving an existing project * Readme contd: Configuration and Testing * Readme contd: Commands * Readme contd: Added some subheadings * New GIF Pronounced with a hard G * Last preparations before pull request - Renamed confusingly named “initialization” shell scripts - Improved Readme layout - bumped version number * Added proper sidebar for the Django DDP project name issue into the README * Added intro section to readme * Added intro section to readme * Fixed conflict in README * Bumping Version Number to 1.0. Oh yeah! * Bumping Version number to 1.0.1.dev1 * Added a check wether docker is installed before initializing. This fixes #15 * Hotfix for a supervisord bug The file supervisord.conf contained a line that referenced the wrong file path for spinup.sh. This hotfix fixes that. Fixes #18. * Updated initialize method to print out more accurate error messages #20 * Added alias "init" for "initialize" command fixed #21 * Improved Help output fixed #11 * Bumped Version Number to 1.0.3 * Bumbed version number to 1.1b1 * Deduplicated help code, moved help its own method This fixes #23 * Added “version” command, and moved the version number to version.py This fixes #22 * Changed “backspace” to a static method This ekes out about 0.0000001% of performance, and also removes a warning in PyCharm. * Improved wording for “direct_deploy” doc string * Updated Version Number to 1.1 --- jonah/bin/jonah | 10 +++----- jonah/jonah.py | 62 +++++++++++++++++++++++++++++------------------- jonah/version.py | 1 + setup.py | 5 ++-- 4 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 jonah/version.py diff --git a/jonah/bin/jonah b/jonah/bin/jonah index f4031fd..eca998a 100644 --- a/jonah/bin/jonah +++ b/jonah/bin/jonah @@ -1,18 +1,14 @@ #!/usr/bin/env python import sys -import jonah +from jonah import Deployer if __name__ == '__main__': - d = jonah.Deployer() + d = Deployer() if len(sys.argv) > 1 and sys.argv[1] in dir(d): if len(sys.argv) > 2 and sys.argv[2] == 'debug': d.debug_mode = True getattr(d, sys.argv[1])() else: - print("USAGE:") - print("\t%s , where command is one of the following:\n" % sys.argv[0]) - - for arg in dir(d): - print("\t" + arg.ljust(10) + "\t" + getattr(d, arg).__doc__) + print(d.help(sys.argv)) exit(0) diff --git a/jonah/jonah.py b/jonah/jonah.py index 58db20b..bff83f9 100755 --- a/jonah/jonah.py +++ b/jonah/jonah.py @@ -7,8 +7,9 @@ import shlex import shutil import textwrap +import version -# requests might now be available. Don't run the "deploy" command in this case +# requests might not be available. Don't run the "deploy" command in this case try: import requests except ImportError: @@ -45,8 +46,32 @@ def __init__(self, config_file_path=os.path.join(os.getcwd(), 'jonah.ini')): @staticmethod def __dir__(**kwargs): - return ['initialize', 'init', 'build', 'clean_build', 'develop', 'compilemessages', 'stop', 'reload', 'shell', 'tag', - 'test', 'stage', 'deploy', 'direct_deploy', 'cleanup'] + return ['initialize', 'init', 'build', 'clean_build', 'develop', 'compilemessages', 'stop', 'reload', 'shell', + 'tag', 'test', 'stage', 'deploy', 'direct_deploy', 'cleanup', 'version'] + + def help(self, argv=('jonah',)): + """Output the help screen""" + output = "Jonah {} -- ".format(version.__version__) + + output += "USAGE:\n" + output += " {} , where is one of the following:\n".format(argv[0]) + + commands = {"General": ['init', 'build', 'clean_build', 'cleanup', 'version'], + "Development": ['develop', 'reload', 'shell', 'stop', 'test', 'compilemessages'], + "Deployment": ['stage', 'deploy', 'tag', 'direct_deploy']} + + for group_name in commands.keys(): + output += "\n {}:\n".format(group_name) + for command_name in commands[group_name]: + command_help = textwrap.wrap(getattr(self, command_name).__doc__, 56) + output += " - {}\t{}\n".format(command_name.ljust(12), command_help[0]) + if len(command_help) > 1: + for additional_line in command_help[1:]: + output += (" " * 20) + "\t" + additional_line + "\n" + + return output + + # Helper Methods ################################################################################################### def run(self, cmd, cwd=None, exceptions_should_bubble_up=False, spew=False): """Run a shell command""" @@ -55,8 +80,8 @@ def run(self, cmd, cwd=None, exceptions_should_bubble_up=False, spew=False): if spew: # return live output for the function to handle instead of one blob - return subprocess.Popen(shlex.split(cmd), cwd=self.working_dir if cwd is None else cwd, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) + return subprocess.Popen(shlex.split(cmd), cwd=self.working_dir if cwd is None else cwd, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) try: return subprocess.check_output(shlex.split(cmd), cwd=self.working_dir if cwd is None else cwd, @@ -91,7 +116,8 @@ def full_name(self, environment): # environment should be 'develop', 'staging', or 'production' return self.get_configuration('DOCKER_IMAGE_NAME', environment) - def backspace(self, string_to_escape): + @staticmethod + def backspace(string_to_escape): if string_to_escape is None: return for char in string_to_escape: @@ -100,6 +126,10 @@ def backspace(self, string_to_escape): # User Actions ##################################################################################################### + def version(self): + """Print out the version number and exit""" + self.printout(version.__version__) + def check_docker(self): """Check that the Docker executable is available on the user's system.""" try: @@ -327,7 +357,7 @@ def stage(self): self.deploy(environment=staging) def direct_deploy(self, environment=production): - """Deploy as tag "master" on production server, without warning and without asking for confirmation. Danger Zone. """ + """Deploy as tag "master" on production server, without warning or asking for confirmation. Danger Zone. """ self.build() self.tag(environment, tag=environment) self.push(environment) @@ -376,21 +406,5 @@ def cleanup(self): d.debug_mode = True getattr(d, sys.argv[1])() else: - print("USAGE:") - print(" {} , where is one of the following:".format(sys.argv[0])) - - commands = {} - commands["General"] = ['init', 'build', 'clean_build', 'cleanup'] - commands["Development"] = ['develop', 'reload', 'shell', 'stop', 'test', 'compilemessages'] - commands["Deployment"] = ['stage', 'deploy', 'tag', 'direct_deploy'] - - for groupname in commands.keys(): - print("\n {}:".format(groupname)) - for command_name in commands[groupname]: - command_help = textwrap.wrap(getattr(d, command_name).__doc__, 56) - print(" - {}\t{}".format(command_name.ljust(12), command_help[0])) - if len(command_help) > 1: - for additional_line in command_help[1:]: - print((" " * 20) + "\t" + additional_line) - + print(d.help(sys.argv)) exit(0) diff --git a/jonah/version.py b/jonah/version.py new file mode 100644 index 0000000..439eb0c --- /dev/null +++ b/jonah/version.py @@ -0,0 +1 @@ +__version__ = '1.1' diff --git a/setup.py b/setup.py index 02ea1e3..04cd956 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,7 @@ # To use a consistent encoding from codecs import open from os import path +from jonah.version import __version__ here = path.abspath(path.dirname(__file__)) @@ -22,7 +23,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='1.0.3', + version=__version__, description='A way to pack your Django Development, Deployment and Testing into Docker', long_description=long_description, @@ -43,7 +44,7 @@ # 3 - Alpha # 4 - Beta # 5 - Production/Stable - 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', # Indicate who your project is intended for 'Intended Audience :: Developers',