Ejemplo n.º 1
0
def summary(*cmdline_args):
    """Print a summary to stdout."""
    from atelier.projects import load_projects
    headers = (
        # ~ '#','Location',
        'Project',
        # 'Old version',
        'Version')

    def cells(self):
        self.load_fabfile()
        # print 20140116, self.module
        desc = "%s -- " % self.nickname
        desc += "(doc_trees : %s)\n" % ', '.join(self.doc_trees)
        url = self.SETUP_INFO.get('url', None)
        version = self.SETUP_INFO.get('version', '')
        if url:
            desc += "`%s <%s>`__ -- %s" % (
                self.name, url,
                self.SETUP_INFO['description'])
        return (
            '\n'.join(textwrap.wrap(desc, 60)),
            # self.dist.version,
            version)

    print(rstgen.table(headers, [cells(p) for p in load_projects()]))
Ejemplo n.º 2
0
def configure(globals_dict):
    # The following will load the `fabfile.py` of other
    # projects. Possible side effects.

    extlinks = dict()
        # linoticket=(
        #     'http://lino-framework.org/tickets/%s.html',
        #     'Lino Ticket #'))
    intersphinx_mapping = dict()
    for prj in load_projects():
        # prj.load_fabfile()
        prj.load_tasks()
        for doc_tree in prj.doc_trees:
            p = prj.root_dir.child(doc_tree, '.build', 'objects.inv')
            if p.exists():
                if doc_tree == 'docs':
                    k = prj.nickname
                else:
                    k = prj.nickname + doc_tree.replace('_', '')
                url = prj.intersphinx_urls.get(doc_tree)
                if url:
                    intersphinx_mapping[k] = (url, p)

        if prj.srcref_url:
            k = '%s_srcref' % prj.nickname
            extlinks[str(k)] = (prj.srcref_url, '')

    globals_dict.update(intersphinx_mapping=intersphinx_mapping)

    if False:  # no longer used
        globals_dict.update(extlinks=extlinks)
Ejemplo n.º 3
0
def commited_today(today=None):
    """Print all today's commits to stdout."""
    from atelier.projects import load_projects
    from git import Repo

    today = get_current_date(today)
    rows = []

    def load(self):

        self.load_fabfile()

        if env.revision_control_system != 'git':
            return
    
        repo = Repo(env.root_dir)

        kw = dict()
        ONEDAY = timedelta(days=1)
        yesterday = today - ONEDAY
        tomorrow = today + ONEDAY
        kw.update(after=yesterday.strftime("%Y-%m-%d"),
                  before=tomorrow.strftime("%Y-%m-%d"))
        it = list(repo.iter_commits(**kw))
        if len(it) == 0:
            return

        def fmtcommit(c):

            url = repo.remotes.origin.url
            if url.startswith("*****@*****.**"):
                url = "https://github.com/" + url[15:-4] \
                      + "/commit/" + c.hexsha
            
            s = "`{0} <{1}>`__".format(c.hexsha[-7:], url)
            if c.message and not c.message.startswith("http://"):
                s += " " + c.message
            return s
            
        url = self.SETUP_INFO.get('url', "oops")
        desc = "`%s <%s>`__" % (self.name, url)

        for c in it:
            ts = time.strftime("%H:%M", time.gmtime(c.committed_date))
            rows.append([ts, desc, fmtcommit(c)])

    for p in load_projects():
        load(p)

    def mycmp(a, b):
        return cmp(a[0], b[0])
    rows.sort(mycmp)
    print(rstgen.ul(["{0} : {1}\n{2}".format(*row) for row in rows]))
Ejemplo n.º 4
0
def configure(globals_dict, prjspec=None, **nicknames):
    """

    Install doctrees of all (or some) atelier projects into the
    :envvar:`intersphinx_mapping` of your :xfile:`conf.py`.

    See :doc:`/sphinxext/interproject`.

    """

    intersphinx_mapping = dict()
    # extlinks = dict()

    # this = atelier.current_project
    # if this is None:
    #     raise Exception("current_project in {} is None!".format(globals_dict['__file__']))

    this_conf_file = Path(globals_dict['__file__']).resolve()

    if prjspec:
        if isinstance(prjspec, str):
            prjspec = prjspec.split()
        prjlist = [get_project_info_from_mod(n) for n in prjspec]

    else:
        prjlist = []
        # for p in load_projects():
        for p in reversed(list(load_projects())):
            if this_conf_file.startswith(p.root_dir):
                # print("20190122 {} startswith  {}".format(this_conf_file, p.root_dir))
                continue
            prjlist.append(p)

    for k, v in nicknames.items():
        p = get_project_from_nickname(k)
        if p:
            prjlist.append(p)
        else:
            intersphinx_mapping[k] = v

    # logger.info("20180907 prjlist {}".format(prjlist))
    for prj in prjlist:
        # This will load the `tasks.py` of other
        # projects. Possible side effects.
        # print("20180428 {} {}".format(prj.name, prj.config['doc_trees']))
        # config = prj.inv_namespace.configuration()
        # print("20180428 {} {}".format(prj.name, config['doc_trees']))
        # ctx = Context(config)
        # for doc_tree in prj.config['doc_trees']:
        count = 0
        for doc_tree in prj.get_doc_trees():
            if not doc_tree.has_intersphinx:
                logger.info("%s has no intersphinx", p)
                continue
            count += 1
            urls = prj.get_xconfig('intersphinx_urls') or {}
            url = urls.get(doc_tree.rel_path)
            if not url:
                if prjspec:
                    logger.warning(
                        "No intersphinx mapping for {} of {} ({})".format(
                            doc_tree.rel_path, prj.nickname, urls))
                continue

            # if prj.nickname == "getlino":
            #     raise Exception("20191003 {}".format(doc_tree.src_path))

            p = None
            src_path = doc_tree.src_path
            if src_path is not None:
                if this_conf_file == src_path.child('conf.py'):
                    # don't add myself to intersphinx.
                    continue

                if USE_LOCAL_BUILDS:
                    # print("20190306a", doc_tree, src_path)
                    # p = prj.root_dir.child(doc_tree, '.build', 'objects.inv')
                    p = src_path.child('.build', 'objects.inv')
                    if p.exists():
                        logger.info("Found local {}".format(p))
                    else:
                        logger.info("File %s does not exist", p)
                        p = None

            # The unique identifier can be used to prefix cross-reference targets
            # http://www.sphinx-doc.org/en/master/ext/intersphinx.html#confval-intersphinx_mapping
            k = prj.nickname + doc_tree.rel_path
            k = k.replace('_', '')
            k = str(k)

            if k in intersphinx_mapping:
                raise Exception("Duplicate intersphinx key {} used for {} "
                                "(you ask to redefine it to {})".format(
                                    k, intersphinx_mapping[k], p))
            intersphinx_mapping[k] = (url, p)

        if count == 0 and prjspec:
            logger.warning("No doctree for {}".format(prj))
        # if prj.srcref_url:
        #     k = '%s_srcref' % prj.nickname
        #     extlinks[str(k)] = (prj.srcref_url, '')

    # atelier.current_project = this
    globals_dict.update(intersphinx_mapping=intersphinx_mapping)
Ejemplo n.º 5
0
def git_projects():
    for prj in load_projects():
        prj.load_info()
        if prj.config['revision_control_system'] == 'git':
            yield prj
Ejemplo n.º 6
0
from atelier.projects import load_projects
for p in load_projects():
    p.load_info()
    locale_dir = p.config['locale_dir']
    if locale_dir:
        print("- :ref:`{}` : {}".format(p.nickname, locale_dir))
Ejemplo n.º 7
0
def git_projects():
    for prj in load_projects():
        prj.load_info()
        if prj.config['revision_control_system'] == 'git':
            yield prj
Ejemplo n.º 8
0
def configure(globals_dict, prjspec=None):

    intersphinx_mapping = dict()
    # extlinks = dict()

    # this = atelier.current_project
    # if this is None:
    #     raise Exception("current_project in {} is None!".format(globals_dict['__file__']))

    this_conf_file = Path(globals_dict['__file__']).resolve()
    
    if prjspec:
        if isinstance(prjspec, six.string_types):
            prjspec = prjspec.split()
        prjlist = [get_project_info_from_mod(n) for n in prjspec]
            
    else:
        prjlist = []
        # for p in load_projects():
        for p in reversed(list(load_projects())):
            if this_conf_file.startswith(p.root_dir):
                # print("20190122 {} startswith  {}".format(this_conf_file, p.root_dir))
                continue
            prjlist.append(p)
        
    # logger.info("20180907 prjlist {}".format(prjlist))
    for prj in prjlist:
        # This will load the `tasks.py` of other
        # projects. Possible side effects.
        # print("20180428 {} {}".format(prj.name, prj.config['doc_trees']))
        # config = prj.inv_namespace.configuration()
        # print("20180428 {} {}".format(prj.name, config['doc_trees']))
        # ctx = Context(config)
        # for doc_tree in prj.config['doc_trees']:
        count = 0
        for doc_tree in prj.get_doc_trees():
            if not doc_tree.has_intersphinx:
                logger.info("%s has no intersphinx", p)
                continue
            count += 1
            urls = prj.get_xconfig('intersphinx_urls') or {}
            url = urls.get(doc_tree.rel_path)
            if not url:
                if prjspec:
                    logger.warning(
                        "No intersphinx mapping for {} of {} ({})".format(
                            doc_tree.rel_path, prj.nickname, urls))
                continue

            p = None
            if USE_LOCAL_BUILDS:
                src_path = doc_tree.src_path
                # print("20190306a", doc_tree, src_path)
                if src_path is None or this_conf_file == src_path.child('conf.py'):
                    continue
                # p = prj.root_dir.child(doc_tree, '.build', 'objects.inv')
                p = src_path.child('.build', 'objects.inv')
                if p.exists():
                    logger.info("Found local {}".format(p))
                else:
                    logger.info("File %s does not exist", p)
                    p = None


            # The unique identifier can be used to prefix cross-reference targets
            # http://www.sphinx-doc.org/en/master/ext/intersphinx.html#confval-intersphinx_mapping
            k = prj.nickname + doc_tree.rel_path
            k = k.replace('_', '')
            k = six.text_type(k)  # make sure it's not newstr from
                                  # future because that can cause
                                  # problems when intersphinx tries to
                                  # sort them

            if k in intersphinx_mapping:
                raise Exception("Duplicate intersphinx key {} used for {} "
                                "(you ask to redefine it to {})".format(
                    k, intersphinx_mapping[k], p))
            intersphinx_mapping[k] = (url, p)

        if count == 0 and prjspec:
            logger.warning("No doctree for {}".format(prj))
        # if prj.srcref_url:
        #     k = '%s_srcref' % prj.nickname
        #     extlinks[str(k)] = (prj.srcref_url, '')

    # atelier.current_project = this
    globals_dict.update(intersphinx_mapping=intersphinx_mapping)
Ejemplo n.º 9
0
def commited_today(ctx, today=None):
    """Print all today's commits to stdout."""
    from atelier.projects import load_projects
    from git import Repo

    today = get_current_date(today)
    rows = []

    def load(prj):

        # prj.load_fabfile()
        prj.load_tasks()

        # tsk, cfg = prj.ns.task_with_config('ci')
        cfg = prj.ns.configuration()

        if cfg['revision_control_system'] != 'git':
            # if cfg.revision_control_system != 'git':
            # print("20160816 {}".format(cfg))
            return

        repo = Repo(cfg['root_dir'])

        kw = dict()
        ONEDAY = timedelta(days=1)
        yesterday = today - ONEDAY
        tomorrow = today + ONEDAY
        kw.update(after=yesterday.strftime("%Y-%m-%d"),
                  before=tomorrow.strftime("%Y-%m-%d"))
        it = list(repo.iter_commits(**kw))
        if len(it) == 0:
            # print("20160816 no commits in {}".format(prj.nickname))
            return

        def fmtcommit(c):

            url = repo.remotes.origin.url
            if url.startswith("*****@*****.**"):
                url = "https://github.com/" + url[15:-4] \
                      + "/commit/" + c.hexsha
            elif url.startswith("git+ssh://[email protected]"):
                url = "https://github.com/" + url[25:-4] \
                      + "/commit/" + c.hexsha

            s = "`{0} <{1}>`__".format(c.hexsha[-7:], url)
            if c.message and not c.message.startswith("http://"):
                s += " " + c.message
            return s

        url = prj.SETUP_INFO.get('url', "oops")
        desc = "`%s <%s>`__" % (prj.name, url)

        for c in it:
            # ts = time.strftime("%H:%M", time.gmtime(c.committed_date))
            ts = time.strftime("%Y-%m-%d %H:%M", time.localtime(c.committed_date))
            rows.append([ts, desc, fmtcommit(c)])

    for p in load_projects():
        load(p)

    def mycmp(a, b):
        return cmp(a[0], b[0])

    rows.sort(mycmp)
    print(rstgen.ul(["{0} : {1}\n{2}".format(*row) for row in rows]))