Exemplo n.º 1
0
def writeNotebook(outfile, options, kwargs,
                  renderer_options,
                  transformer_options,
                  display_options,
                  modulename, name):
    '''write a snippet to paste with the ipython notebook.
    '''

    cmd_options = [
        'do_print = False',
        'tracker="%s"' % options.tracker,
        'renderer="%s"' % options.renderer,
        'trackerdir="%s"' % options.trackerdir,
        'workdir="%s"' % os.getcwd()]

    for key, val in list(kwargs.items()) +\
            list(renderer_options.items()) +\
            list(transformer_options.items()):
        if val is None:
            cmd_options.append("%s" % key)
        else:
            if Utils.isString(val):
                cmd_options.append('%s="%s"' % (key, val))
            else:
                cmd_options.append('%s=%s' % (key, val))
    if options.transformers:
        cmd_options.append(
            "transformer=['%s']" % "','".join(options.transformers))

    # no module name in tracker
    params = {"tracker": "%s" % (name),
              "options": ",\n".join(cmd_options)}

    outfile.write(Utils.NOTEBOOK_TEXT_TEMPLATE % params)
Exemplo n.º 2
0
def path2str(path):
    '''convert path to printable string.'''
    if path is None:
        return ""
    if Utils.isString(path):
        return path
    try:
        return "/".join(map(str, path))
    except:
        return str(path)
Exemplo n.º 3
0
    def _match(self, label, paths):
        '''return True if any of paths match to label.'''

        for s in paths:
            if label == s:
                return True
            elif s.startswith("r(") and s.endswith(")"):
                    # collect pattern matches:
                    # remove r()
                    s = s[2:-1]
                    # remove flanking quotation marks
                    if s[0] in ('"', "'") and s[-1] in ('"', "'"):
                        s = s[1:-1]
                    rx = re.compile(s)
                    if not Utils.isString(label):
                        continue
                    if rx.search(label):
                        return True
        return False