Beispiel #1
0
def main(
    config_vars,
    argv=sys.argv,
    default_config_file_path="config.py",
    project_name=None,
    doc=None,
    serialize_header_cb=None,
):
    """A main() function for a configure.py.

        "config_vars" is a list of configuration variables -- each one
            an instance of configurelib.ConfigVar.
        "argv" (optional, default sys.argv) is the command line args array.
        "default_config_file_path" (optional) is the path to which the
            configuration will be serialized. By default this is "config.py",
            but it is recommended that a project-specific name along the
            lines of "${projprefix}config.py" be specified. E.g. ActivePython
            might use "apyconfig.py", Komodo might use "koconfig.py". This
            can be overridden with the '-f' option.
        "project_name" (optional) is the name of the project that will use
            this configuration.
        "doc" (optional) is a description for help output for the
            configure.py script.
        "serialize_header_cb" (optional) is a callback for adding to the
            serialization stream. It is called as
            "serialize_header_cb(format, stream)".
    """
    try:
        setup_logging()
        retval = configure(config_vars, argv, default_config_file_path, project_name, doc, serialize_header_cb)
    except KeyboardInterrupt:
        sys.exit(1)
    except SystemExit:
        raise
    except:
        # TODO: see diffs with doitlib/runner.py
        exc_info = sys.exc_info()
        if hasattr(exc_info[0], "__name__"):
            exc_class, exc, tb = exc_info
            tb_path, tb_lineno, tb_func = traceback.extract_tb(tb)[-1][:3]
            exc_str = str(exc_info[1])
            sep = "\n" in exc_str and "\n" or " "
            try:
                from mklib.common import relpath
            except ImportError:

                def relpath(path):
                    return path

            log.error("%s%s(%s:%s in %s)", exc_str, sep, relpath(tb_path), tb_lineno, tb_func)
        else:  # string exception
            log.error(exc_info[0])
        if log.isEnabledFor(logging.DEBUG):
            print
            traceback.print_exception(*exc_info)
        sys.exit(1)
    else:
        sys.exit(retval)
Beispiel #2
0
 def nicepath(self):
     a = self.path
     r = relpath(self.path)
     if not sys.platform == "win32" and isabs(a):
         home = os.environ["HOME"]
         if a.startswith(home):
             #XXX:TODO: bug here for, e.g., "/home/jan" vs "/home/jane"
             a = "~" + a[len(home):]
     if len(r) < len(a):
         return r
     else:
         return a
Beispiel #3
0
 def nicepath(self):
     a = self.path
     r = relpath(self.path)
     if not sys.platform == "win32" and isabs(a):
         home = os.environ["HOME"]
         if a.startswith(home):
             #XXX:TODO: bug here for, e.g., "/home/jan" vs "/home/jane"
             a = "~" + a[len(home):]
     if len(r) < len(a):
         return r
     else:
         return a
Beispiel #4
0
def main(config_vars, argv=sys.argv, default_config_file_path="config.py",
         project_name=None, doc=None, serialize_header_cb=None):
    """A main() function for a configure.py.

        "config_vars" is a list of configuration variables -- each one
            an instance of configurelib.ConfigVar.
        "argv" (optional, default sys.argv) is the command line args array.
        "default_config_file_path" (optional) is the path to which the
            configuration will be serialized. By default this is "config.py",
            but it is recommended that a project-specific name along the
            lines of "${projprefix}config.py" be specified. E.g. ActivePython
            might use "apyconfig.py", Komodo might use "koconfig.py". This
            can be overridden with the '-f' option.
        "project_name" (optional) is the name of the project that will use
            this configuration.
        "doc" (optional) is a description for help output for the
            configure.py script.
        "serialize_header_cb" (optional) is a callback for adding to the
            serialization stream. It is called as
            "serialize_header_cb(format, stream)".
    """
    try:
        setup_logging()
        retval = configure(config_vars, argv, default_config_file_path,
                           project_name, doc, serialize_header_cb)
    except KeyboardInterrupt:
        sys.exit(1)
    except SystemExit:
        raise
    except:
        #TODO: see diffs with doitlib/runner.py
        exc_info = sys.exc_info()
        if hasattr(exc_info[0], "__name__"):
            exc_class, exc, tb = exc_info
            tb_path, tb_lineno, tb_func = traceback.extract_tb(tb)[-1][:3]
            exc_str = str(exc_info[1])
            sep = ('\n' in exc_str and '\n' or ' ')
            try:
                from mklib.common import relpath
            except ImportError:
                def relpath(path):
                    return path
            log.error("%s%s(%s:%s in %s)", exc_str, sep,
                      relpath(tb_path), tb_lineno, tb_func)
        else:  # string exception
            log.error(exc_info[0])
        if log.isEnabledFor(logging.DEBUG):
            print
            traceback.print_exception(*exc_info)
        sys.exit(1)
    else:
        sys.exit(retval)
Beispiel #5
0
def include(makefile_path, ns=None):
    # Makefile loading places some state on the module at '_mk_*_'
    # attributes.
    f = sys._getframe(1)
    parent = f.f_globals["_mk_makefile_"]

    # If the included path is relative it must be relative to the
    # including Makefile.
    if not isabs(makefile_path):
        parent_makefile_dir = dirname(f.f_code.co_filename)
        makefile_path = normpath(join(relpath(parent_makefile_dir),
                                      makefile_path))

    ns_str = ns and " (ns=%r)" % ns or ""
    log.debug("include makefile `%s'%s", makefile_path, ns_str)

    #TODO: not sure what todo about config_file_path_override (defer)
    ns_list = (parent.ns or []) + (ns and [ns] or [])
    makefile = Makefile(makefile_path, parent.master, ns=ns_list,
                        parent=parent)
    parent.includes.append(makefile)
Beispiel #6
0
def include(makefile_path, ns=None):
    # Makefile loading places some state on the module at '_mk_*_'
    # attributes.
    f = sys._getframe(1)
    parent = f.f_globals["_mk_makefile_"]

    # If the included path is relative it must be relative to the
    # including Makefile.
    if not isabs(makefile_path):
        parent_makefile_dir = dirname(f.f_code.co_filename)
        makefile_path = normpath(
            join(relpath(parent_makefile_dir), makefile_path))

    ns_str = ns and " (ns=%r)" % ns or ""
    log.debug("include makefile `%s'%s", makefile_path, ns_str)

    #TODO: not sure what todo about config_file_path_override (defer)
    ns_list = (parent.ns or []) + (ns and [ns] or [])
    makefile = Makefile(makefile_path,
                        parent.master,
                        ns=ns_list,
                        parent=parent)
    parent.includes.append(makefile)
Beispiel #7
0
 def make(self):
     src = self.deps[0].path
     dst = self.results[0].path
     self.log.info("cp %s %s", relpath(src), relpath(dst))
     shutil.copy(src, dst)
Beispiel #8
0
 def make(self):
     for result in self.results:
         print "touch %s" % relpath(result.path)
Beispiel #9
0
 def make(self):
     src = self.deps[0].path
     dst = self.results[0].path
     self.log.info("cp %s %s", relpath(src), relpath(dst))
     shutil.copy(src, dst)