Artifact [8ab9ab634f]
Not logged in

Artifact 8ab9ab634ff678cf3d26a9b30bf0321a0d1cd763:


#!/usr/bin/env python
#
# @file  morg.py
# @brief Morg TODO list manager's main function and related code.
#

#
# Copyright (C) 2014 The Morg Project Developers
#
# See wiki/copyright.wiki in the top-level directory of the Morg source
# distribution for the full list of authors who have contributed to this
# project.
#

#
# This file is part of Morg.
#
# Morg is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# Morg is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with Morg. If not, see <http://www.gnu.org/licenses/>.
#

#------------------------------- IMPORTS --------------------------------

# Morg library
import morglib

# Standard library
import logging
import os
import sys

#--------------------------- PROGRAM VERSION ----------------------------

# NOTE: Update the major, minor, and patch variables in this class when
# making a release, i.e., only on the rel branch. On the dev branch, let
# them remain all zeros.
class version:
    '''A helper class to encapsulate Morg's version info.

    Morg's version number is of the form "a.b.c", where "a" is the major
    number, "b" the minor number, and "c" the patch level.

    The three components are maintained as separate integers in this
    class. Thus, a client using Morg as a library rather than an
    application could potentially perform something akin to the
    following:

    @code
        import sys
        import morg
        v = morg.version()
        if (v.major < 2):
            print('Morg version is {}; need >= 2.0.0'.format(v))
            sys.exit(1)
    @endcode

    @note We only set Morg version numbers on formal releases. Thus, if
    you see Morg's version as 0.0.0, you're working with a development
    version of Morg.

    '''
    major = 0
    minor = 0
    patch = 0

    def __str__(self):
        return '{}.{}.{}'.format(self.major, self.minor, self.patch)

#---------------------------- MODULE LOGGER -----------------------------

logger = logging.getLogger(__name__)

#-------------------------------- MAIN ----------------------------------

def main():
    try:
        args = morglib.args.parse(sys.argv[1:], str(version()))
        morglib.log.init(args.debug_level, args.log_file)
        logger.info('starting Morg')
        morglib.args.dump(args)

        if (args.command):
            morglib.interpreter.execute(args.command[0], args.command)
        else:
            morglib.command.repl(morglib.interpreter)

    except morglib.args.args_error, e:
        sys.stderr.write('{}: {}\n'.
                         format(os.path.basename(sys.argv[0]), e))
        sys.exit(2)

    except morglib.error, e:
        logger.error(e)
        sys.stderr.write('{}: {}\n'.
                         format(os.path.basename(sys.argv[0]), e))
        sys.exit(1)


if (__name__ == "__main__"):
    main()

#------------------------------------------------------------------------

##############################################
# Editor config:                             #
##############################################
# Local Variables:                           #
# indent-tabs-mode: nil                      #
# py-indent-offset: 4                        #
# python-indent: 4                           #
# End:                                       #
##############################################
# vim: set expandtab shiftwidth=4 tabstop=4: #
##############################################