From 411b36598716306111f520b80226292866f836ae Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Wed, 26 Nov 2014 09:09:19 +0100 Subject: [PATCH 1/4] template for argparse program imported; will be changed to make PyLoT (build, install, re- or uninstall); --- makePyLoT.py | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 makePyLoT.py diff --git a/makePyLoT.py b/makePyLoT.py new file mode 100644 index 00000000..aceb981b --- /dev/null +++ b/makePyLoT.py @@ -0,0 +1,140 @@ +#!/usr/local/bin/python2.7 +# encoding: utf-8 +''' +makePyLoT -- build and install PyLoT + +makePyLoT is a python make file in order to establish the folder structure and +meet requisites + +It defines +:class CLIError: +:method main: + +:author: Sebastian Wehling-Benatelli + +:copyright: 2014 MAGS2 EP3 Working Group. All rights reserved. + +:license: GNU Lesser General Public License, Version 3 + (http://www.gnu.org/copyleft/lesser.html) + +:contact: sebastian.wehling@rub.de + +updated: Updated +''' + +import sys +import os + +from argparse import ArgumentParser +from argparse import RawDescriptionHelpFormatter + +__all__ = [] +__version__ = 0.1 +__date__ = '2014-11-26' +__updated__ = '2014-11-26' + +DEBUG = 1 +TESTRUN = 0 +PROFILE = 0 + +class CLIError(Exception): + '''Generic exception to raise and log different fatal errors.''' + def __init__(self, msg): + super(CLIError).__init__(type(self)) + self.msg = "E: %s" % msg + def __str__(self): + return self.msg + def __unicode__(self): + return self.msg + +def main(argv=None): # IGNORE:C0111 + '''Command line options.''' + + if argv is None: + argv = sys.argv + else: + sys.argv.extend(argv) + + program_name = os.path.basename(sys.argv[0]) + program_version = "v%s" % __version__ + program_build_date = str(__updated__) + program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) + program_shortdesc = __import__('__main__').__doc__.split("\n")[1] + program_license = '''%s + + Created by Sebastian Wehling-Benatelli on %s. + Copyright 2014 MAGS2 EP3 Working Group. All rights reserved. + + GNU Lesser General Public License, Version 3 + (http://www.gnu.org/copyleft/lesser.html) + + Distributed on an "AS IS" basis without warranties + or conditions of any kind, either express or implied. + +USAGE +''' % (program_shortdesc, str(__date__)) + + try: + # Setup argument parser + parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) + parser.add_argument("-r", "--recursive", dest="recurse", action="store_true", help="recurse into subfolders [default: %(default)s]") + parser.add_argument("-v", "--verbose", dest="verbose", action="count", help="set verbosity level [default: %(default)s]") + parser.add_argument("-i", "--include", dest="include", help="only include paths matching this regex pattern. Note: exclude is given preference over include. [default: %(default)s]", metavar="RE" ) + parser.add_argument("-e", "--exclude", dest="exclude", help="exclude paths matching this regex pattern. [default: %(default)s]", metavar="RE" ) + parser.add_argument('-V', '--version', action='version', version=program_version_message) + parser.add_argument(dest="paths", help="paths to folder(s) with source file(s) [default: %(default)s]", metavar="path", nargs='+') + + # Process arguments + args = parser.parse_args() + + paths = args.paths + verbose = args.verbose + recurse = args.recurse + inpat = args.include + expat = args.exclude + + if verbose > 0: + print("Verbose mode on") + if recurse: + print("Recursive mode on") + else: + print("Recursive mode off") + + if inpat and expat and inpat == expat: + raise CLIError("include and exclude pattern are equal! Nothing will be processed.") + + for inpath in paths: + ### do something with inpath ### + print(inpath) + return 0 + except KeyboardInterrupt: + ### handle keyboard interrupt ### + return 0 + except Exception, e: + if DEBUG or TESTRUN: + raise(e) + indent = len(program_name) * " " + sys.stderr.write(program_name + ": " + repr(e) + "\n") + sys.stderr.write(indent + " for help use --help") + return 2 + +if __name__ == "__main__": + if DEBUG: + sys.argv.append("-h") + sys.argv.append("-v") + sys.argv.append("-r") + if TESTRUN: + import doctest + doctest.testmod() + if PROFILE: + import cProfile + import pstats + profile_filename = 'makePyLoT_profile.txt' + cProfile.run('main()', profile_filename) + statsfile = open("profile_stats.txt", "wb") + p = pstats.Stats(profile_filename, stream=statsfile) + stats = p.strip_dirs().sort_stats('cumulative') + stats.print_stats() + statsfile.close() + sys.exit(0) + sys.exit(main()) \ No newline at end of file From c7f09988e57b458894f87b0a5c93be7575bfe8c9 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Thu, 27 Nov 2014 11:51:40 +0100 Subject: [PATCH 2/4] started implementation of a makePyLoT routine capable of building and installing PyLoT to a desired directory --- makePyLoT.py | 57 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/makePyLoT.py b/makePyLoT.py index aceb981b..b1b390dc 100644 --- a/makePyLoT.py +++ b/makePyLoT.py @@ -33,7 +33,7 @@ __version__ = 0.1 __date__ = '2014-11-26' __updated__ = '2014-11-26' -DEBUG = 1 +DEBUG = 0 TESTRUN = 0 PROFILE = 0 @@ -58,7 +58,7 @@ def main(argv=None): # IGNORE:C0111 program_name = os.path.basename(sys.argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) - program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) + program_version_message = '%makePyLoT %s (%s)' % (program_version, program_build_date) program_shortdesc = __import__('__main__').__doc__.split("\n")[1] program_license = '''%s @@ -77,38 +77,35 @@ USAGE try: # Setup argument parser parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) - parser.add_argument("-r", "--recursive", dest="recurse", action="store_true", help="recurse into subfolders [default: %(default)s]") - parser.add_argument("-v", "--verbose", dest="verbose", action="count", help="set verbosity level [default: %(default)s]") - parser.add_argument("-i", "--include", dest="include", help="only include paths matching this regex pattern. Note: exclude is given preference over include. [default: %(default)s]", metavar="RE" ) - parser.add_argument("-e", "--exclude", dest="exclude", help="exclude paths matching this regex pattern. [default: %(default)s]", metavar="RE" ) + parser.add_argument("-b", "--build", dest="build", action="store_true", help="build PyLoT") + parser.add_argument("-v", "--verbose", dest="verbose", action="count", help="set verbosity level") + parser.add_argument("-i", "--install", dest="install", action="store_true", help="install PyLoT on the system") + parser.add_argument("-d", "--directory", dest="directory", help="installation directory", metavar="RE" ) parser.add_argument('-V', '--version', action='version', version=program_version_message) - parser.add_argument(dest="paths", help="paths to folder(s) with source file(s) [default: %(default)s]", metavar="path", nargs='+') # Process arguments args = parser.parse_args() - paths = args.paths verbose = args.verbose - recurse = args.recurse - inpat = args.include - expat = args.exclude + build = args.build + install = args.install + directory = args.directory if verbose > 0: print("Verbose mode on") - if recurse: - print("Recursive mode on") - else: - print("Recursive mode off") - - if inpat and expat and inpat == expat: - raise CLIError("include and exclude pattern are equal! Nothing will be processed.") - - for inpath in paths: - ### do something with inpath ### - print(inpath) + if install and not directory: + raise CLIError("trying to install without destination; please specify an installation directory") + if build and install: + print("Building and installing PyLoT ...") + buildPyLoT() + installPyLoT() + elif build and not install: + print("Building PyLoT without installing! Please wait ...") + buildPyLoT() + cleanUp() return 0 except KeyboardInterrupt: - ### handle keyboard interrupt ### + cleanUp() return 0 except Exception, e: if DEBUG or TESTRUN: @@ -118,11 +115,23 @@ USAGE sys.stderr.write(indent + " for help use --help") return 2 +def buildPyLoT(): + if sys.platform.startswith('win' or 'microsoft'): + raise CLIError("building on Windows system not tested yet; implementation pending") + elif sys.platform == 'darwin': + pass + + +def installPyLoT(): + pass + +def cleanUp(): + pass + if __name__ == "__main__": if DEBUG: sys.argv.append("-h") sys.argv.append("-v") - sys.argv.append("-r") if TESTRUN: import doctest doctest.testmod() From 04e6a51e99b34a586e9d4c0788eeeca4e55de739 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Sat, 29 Nov 2014 11:39:25 +0100 Subject: [PATCH 3/4] edit on makePyLoT.py: a symlink is created an darwin systems in order to get the right application name on Mac OS X's menubar --- makePyLoT.py | 13 ++++++++++--- pylot/RELEASE-VERSION | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/makePyLoT.py b/makePyLoT.py index b1b390dc..1328b6f2 100644 --- a/makePyLoT.py +++ b/makePyLoT.py @@ -1,4 +1,4 @@ -#!/usr/local/bin/python2.7 +#!/usr/bin/env python # encoding: utf-8 ''' makePyLoT -- build and install PyLoT @@ -22,8 +22,9 @@ It defines updated: Updated ''' -import sys +import glob import os +import sys from argparse import ArgumentParser from argparse import RawDescriptionHelpFormatter @@ -119,7 +120,13 @@ def buildPyLoT(): if sys.platform.startswith('win' or 'microsoft'): raise CLIError("building on Windows system not tested yet; implementation pending") elif sys.platform == 'darwin': - pass + # create a symbolic link to the desired python interpreter in order to + # display the right application name + for path in os.getenv('PATH').split(':'): + found = glob.glob(os.path.join(path, 'python')) + if found: + os.symlink(found, 'PyLoT') + break def installPyLoT(): diff --git a/pylot/RELEASE-VERSION b/pylot/RELEASE-VERSION index c7992fb6..8c5cb386 100644 --- a/pylot/RELEASE-VERSION +++ b/pylot/RELEASE-VERSION @@ -1 +1 @@ -0.0.0-g4b7b +c7f0-dirty From 609005433aa9e5e8d114d71557e32017a6f3ffb0 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Tue, 2 Dec 2014 12:07:02 +0100 Subject: [PATCH 4/4] added verbose output functionality --- makePyLoT.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/makePyLoT.py b/makePyLoT.py index 1328b6f2..0a37acd4 100644 --- a/makePyLoT.py +++ b/makePyLoT.py @@ -95,18 +95,20 @@ USAGE if verbose > 0: print("Verbose mode on") if install and not directory: - raise CLIError("trying to install without destination; please specify an installation directory") + raise CLIError("""Trying to install without appropriate + destination; please specify an installation + directory!""") if build and install: - print("Building and installing PyLoT ...") - buildPyLoT() - installPyLoT() + print("Building and installing PyLoT ...\n") + buildPyLoT(verbose) + installPyLoT(verbose) elif build and not install: - print("Building PyLoT without installing! Please wait ...") - buildPyLoT() + print("Building PyLoT without installing! Please wait ...\n") + buildPyLoT(verbose) cleanUp() return 0 except KeyboardInterrupt: - cleanUp() + cleanUp(verbose) return 0 except Exception, e: if DEBUG or TESTRUN: @@ -116,23 +118,30 @@ USAGE sys.stderr.write(indent + " for help use --help") return 2 -def buildPyLoT(): - if sys.platform.startswith('win' or 'microsoft'): +def buildPyLoT(verbosity=None): + system = sys.platform + if verbosity > 1: + msg = ("... on system: {0}\n" + "\n" + " Current working directory: {1}\n" + ).format(system, os.getcwd()) + print msg + if system.startswith(('win', 'microsoft')): raise CLIError("building on Windows system not tested yet; implementation pending") - elif sys.platform == 'darwin': + elif system == 'darwin': # create a symbolic link to the desired python interpreter in order to # display the right application name for path in os.getenv('PATH').split(':'): found = glob.glob(os.path.join(path, 'python')) if found: - os.symlink(found, 'PyLoT') + os.symlink(found, './PyLoT') break -def installPyLoT(): +def installPyLoT(verbosity=None): pass -def cleanUp(): +def cleanUp(verbosity=None): pass if __name__ == "__main__":