Commits

Antonio Alvarado Hernández committed f0dba18

minor changes to make them looks like pip

* modified the startup code

  • Participants
  • Parent commits 0e8b320

Comments (0)

Files changed (2)

 
 from argparse import ArgumentParser, ArgumentError, FileType
 
+import os
 import sys
 import json
-import os.path
+import logging
 
 from wa.engines.coremetrics import CmEngine, CmSource
 
     """An interface common to all shell objects."""
 
     def __init__(self):
-        print("Voy from BaseShell...")
-        pass
+        """Common initialization for all shell subclasses."""
+        self.log = logging.getLogger(__name__)
 
-    def run(self):
+    def main(self):
         """Execute the main's shell sequence."""
         raise NotImplementedError()
 
 class BasicShell(BaseShell):
     """A simple implementation of the shell class."""
 
-    def __init___(self, program=r'washell'):
-        """Initializes given shell instance."""
-        print("Voy from BasicShell...")
-        super(BasicShell, self).__init__()
-        self._program = program
+    def __init__(self, name=None):
+        """Initialize given basic shell instance."""
+        super().__init__()
 
-    def run(self):
+    def main(self, args):
         """Implement the main's shell sequence."""
-        print("Running: {}".format(self._program))
+        self.log.debug("Running the shell: {0}".format(str(args)))
         return E_NONE
 
 class BasicShellx(object):
             sources[source['name']] = CmSource(source['parameters'])
         return sources
 
-def create_default_shell():
-    """A factory method to create a shell object."""
-    return BasicShell()
+def main(args):
+    """This is the shell's entry-point."""
 
-def main():
-    """This is the shell's entry-point."""
-    sh = create_default_shell()
-    sh.run()
+    # create a basic shell and run its main method
+    sh = BasicShell()
+    return sh.main(args)
 
 # EOF
-#!/usr/bin/env python3
+#!/usr/bin/env python3 -t
 # -*- coding: utf-8 -*-
 #
 # Copyright 2012,2013 Antonio Alvarado Hernández
 # under the License.
 #
 
-from logging import basicConfig, info, critical, INFO
+import sys
+import logging
 
-import sys
+# define some constants
 
-basicConfig(level=INFO, datefmt="%Y-%m-%d %H:%M:%S",
-    format="%(asctime)s [%(levelname)s]: %(message)s")
+E_BADINSTALL = -1
+E_CANCELLED = 1
 
+# initializes the log subsystem
+loglevel = logging.DEBUG
+logdate = "%Y-%m-%d %H:%M:%S"
+logformat = "%(asctime)s [%(levelname)s]: %(message)s"
+logging.basicConfig(level=loglevel, datefmt=logdate, format=logformat)
+
+# attempt to run the shell
 try:
     from wa import shell
 
-    shell.main()
+    status = shell.main(sys.argv[1:])
+    if status:
+        sys.exit(status)
+
+except ImportError:
+    logging.critical("unable to load the washell's main module ({0})". \
+        format(sys.exc_info()[1]))
+    sys.exit(E_BADINSTALL)
 
 except KeyboardInterrupt:
-    info("exiting on user cancel")
-    sys.exit(0)
-
-except ImportError:
-    critical("unable to load the washell's main module: {0}". \
-        format(sys.exc_info()[1]))
-    sys.exit(1)
+    ## FIXME: premature, move this to the base shell or command
+    logging.info("the operation was cancelled by the user")
+    sys.exit(E_CANCELLED)
 
 # EOF