Пример #1
0
    o_path = os.path.abspath("/".join(["output", "v6", theme]))
    if os.path.isdir(t_path):
        shutil.rmtree(t_path)
    if os.path.isdir(o_path):
        shutil.rmtree(o_path)
    subprocess.check_call(["nikola", "init", "--demo", t_path], stdout=subprocess.PIPE)
    os.symlink(os.path.abspath("themes"), os.path.abspath("/".join([t_path, "themes"])))

    conf_path = "/".join([t_path,"conf.py"])
    # Get custom required settings from the theme
    themes = utils.get_theme_chain(theme)
    extra_conf_path = utils.get_asset_path('conf.py.sample', themes)
    extra_conf = ''
    if extra_conf_path:
        extra_conf = open(extra_conf_path, 'r').read()

    with codecs.open(conf_path, "a", "utf-8") as conf:
        conf.write("\n\n{2}\n\nTHEME = '{0}'\n\nOUTPUT_FOLDER = '{1}'\n\nSOCIAL_BUTTONS_CODE = ''\n".format(theme, o_path, extra_conf))

@contextmanager
def cd(path):
    old_dir = os.getcwd()
    os.chdir(path)
    yield
    os.chdir(old_dir)

if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(build_theme)
Пример #2
0
        elif m_if_end:
            output += m_if_end.expand(r'\1{% endif %}\2') + '\n'

        elif m_for_start:
            output += m_for_start.expand(r'\1{% for \2 %}\3') + '\n'
        elif m_for_end:
            output += m_for_end.expand(r'\1{% endfor %}\2') + '\n'

        elif m_namspace:
            output += m_namspace.expand(r"\1{% import '\3' as \2 with context %}\4") + '\n'
        elif m_inherit:
            output += m_inherit.expand(r"{% extends '\2' %}\3") + '\n'

        elif m_block_single_line:
            output += m_block_single_line.expand(r'\1{% block \2 %}\3{% endblock %}\4') + '\n'
        elif m_block_start:
            output += m_block_start.expand(r'\1{% block \2 %}\3') + '\n'
        elif m_block_end:
            output += m_block_end.expand(r'\1{% endblock %}\2') + '\n'

        else:
            # Doesn't match anything we're going to process, pass though
            output += line

    return output

if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(jinjify)
Пример #3
0
    for l in lineas:
        yield(l[desde:hasta])


def selecciona_fragmento(lineas, fila1=0, fila2=sys.maxint, col1=None, col2=None):
    u"""Filtra el texto dejando solo lo seleccionado.

    La selección es un "rectángulo" marcado por las filas
    y columnas especificadas.

    >>> datos = ("ornitorrinco",) * 10
    >>> list(selecciona_fragmento(datos, 0, 5, 5, 10))
    ['orrin', 'orrin', 'orrin', 'orrin', 'orrin']
    >>> list(selecciona_fragmento(datos, 0, 5, 0, None))
    ['ornitorrinco', 'ornitorrinco', 'ornitorrinco', 'ornitorrinco', 'ornitorrinco']
    """

    lineas = selecciona_lineas(lineas, fila1, fila2)
    resultado = selecciona_columnas(lineas, col1, col2)
    return resultado

def procesa_archivo(archivo, fila1=0, fila2=sys.maxint, col1=None, col2=None):
    u"""Abre un archivo y lo corta según se pida."""

    selecciona_fragmento(open(archivo), fila1, fila2, col1, col2)


if __name__ == "__main__":
   import commandline
   commandline.run_as_main(procesa_archivo)   
Пример #4
0
def read_theme(theme):
    # Gather this theme's data
    theme_name = os.path.basename(theme)
    data = {}
    data['name'] = theme_name
    readme = os.path.join(theme, 'README.md')
    if os.path.isfile(readme):
        with codecs.open(readme, 'r', 'utf8') as inf:
            data['readme'] = inf.read()
    else:
        data['readme'] = ''

    themes = utils.get_theme_chain(theme_name)
    data['engine'] = utils.get_template_engine(themes)


    if 'bootstrap3' in themes:
        data['bs_version'] = 3
    elif 'bootstrap' in themes:
        data['bs_version'] = 2
    else:
        data['bs_version'] = 0

def error(msg):
    print(colorama.Fore.RED + "ERROR:" + msg)

if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(create_site)
Пример #5
0
    if not os.path.isdir(os.path.join("output", "v6")):
        os.mkdir(os.path.join("output", "v6"))

    if os.path.isdir('plugins/' + plugin):
        with cd('plugins/'):
            subprocess.check_call('zip -r ../output/v6/{0}.zip '
                                  '{0}'.format(plugin), stdout=subprocess.PIPE,
                                  shell=True)

    plugins_dict = {}
    for plugin in glob.glob('plugins/*/'):
        t_name = os.path.basename(plugin[:-1])
        plugins_dict[t_name] = BASE_URL + t_name + ".zip"
    with open(os.path.join("output", "v6", "plugins.json"), "wb+") as outf:
        json.dump(plugins_dict, outf, indent=4, ensure_ascii=True,
                  sort_keys=True)


@contextmanager
def cd(path):
    old_dir = os.getcwd()
    os.chdir(path)
    yield
    os.chdir(old_dir)

if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(build_plugin)
Пример #6
0
    t_path = "/".join(["sites", theme])
    o_path = os.path.abspath("/".join(["output", "v6", theme]))
    if os.path.isdir(t_path):
        shutil.rmtree(t_path)
    if os.path.isdir(o_path):
        shutil.rmtree(o_path)
    subprocess.check_call(["nikola", "init", "--demo", t_path],
                          stdout=subprocess.PIPE)
    os.symlink(os.path.abspath("themes"),
               os.path.abspath("/".join([t_path, "themes"])))

    conf_path = "/".join([t_path, "conf.py"])
    with codecs.open(conf_path, "a", "utf-8") as conf:
        conf.write(
            "\n\nTHEME = '{0}'\n\nOUTPUT_FOLDER = '{1}'\n\nSOCIAL_BUTTONS_CODE = ''\n"
            .format(theme, o_path))


@contextmanager
def cd(path):
    old_dir = os.getcwd()
    os.chdir(path)
    yield
    os.chdir(old_dir)


if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(build_theme)
Пример #7
0
    # Gather this theme's data
    theme_name = os.path.basename(theme)
    data = {}
    data['name'] = theme_name
    readme = os.path.join(theme, 'README')
    if os.path.isfile(readme):
        with codecs.open(readme, 'r', 'utf8') as inf:
            data['readme'] = inf.read()
    else:
        data['readme'] = ''

    themes = utils.get_theme_chain(theme_name)
    data['engine'] = utils.get_template_engine(themes)


    if 'bootstrap3' in themes:
        data['bs_version'] = 3
    elif 'bootstrap' in themes:
        data['bs_version'] = 2
    else:
        data['bs_version'] = 0
    print data

def error(msg):
    print(colorama.Fore.RED + "ERROR:" + msg)

if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(create_site)
Пример #8
0
    if os.path.exists(readme):
        data['readme'] = codecs.open(readme, 'r', 'utf8').read()
    else:
        data['readme'] = 'No README.md file available.'

    if os.path.exists(conf_sample):
        data['confpy'] = pygments.highlight(
            codecs.open(conf_sample, 'r', 'utf8').read(),
            PythonLexer(), HtmlFormatter(cssclass='code'))
    else:
        data['confpy'] = None

    if os.path.exists(reqpy):
        data['pyreqs'] = codecs.open(reqpy, 'r', 'utf8').readlines()
    else:
        data['pyreqs'] = []

    if os.path.exists(reqnonpy):
        r = codecs.open(reqnonpy, 'r', 'utf8').readlines()

        data['nonpyreqs'] = [i.strip().split('::') for i in r]
    else:
        data['nonpyreqs'] = []

    return data

if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(build_site)
Пример #9
0
                    error("theme '{0}' contains deprecated name '{1}' in {2}".format(theme, k, path))

    # Ensure the theme has a README
    if utils.get_asset_path('README', [theme]) is None:
        error("theme '{0}' has no README".format(theme))

def is_asset_duplicated(path, themes):
    # First get the path for the asset with whole theme chain
    p1 = utils.get_asset_path(path, themes)
    # Get the path for asset with truncated theme chain
    p2 = utils.get_asset_path(path, themes[1:])
    # Compare
    if p1 and p2:
        return filecmp.cmp(p1, p2, False), p1, p2
    else:
        return False, p1, p2


blacklist = (
    ["${analytics}",[]],
    ["{{analytics}}",[]],
    ["disqus_",['comments_helper.tmpl', 'disqus_helper.tmpl']],
    ["addthis",[]],
    ["namespace file=",[]],
)

if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(sanity_check)
Пример #10
0
            os.system('mpc next')
        elif action == 'prev':
            os.system('mpc prev')
        elif action == 'random':
            os.system('mpc random')
            os.system('mpc next')
        with open('/dev/shm/ui_input.txt', 'w') as fd:
            fd.write(get_mpc_status())
            fd.close()
    elif mode == 'stream':
        stream_uri = get_stream_uri(target)
        if stream_uri:
            os.system('pkill mplayer')
            os.system('mpc stop')
            os.system('mplayer ' + stream_uri + '< /dev/null >/dev/null 2>&1 &')
        with open('/dev/shm/ui_input.txt', 'w') as fd:
            fd.write(get_stream_status())
            fd.close()
            
    elif mode == 'general':
        if target == 'stop':
            os.system('pkill mplayer')
            os.system('mpc stop')
            with open('/dev/shm/ui_input.txt', 'w') as fd:
                fd.write("NO AUDIO")
                fd.close()

if __name__ == "__main__":
   import commandline
   commandline.run_as_main(main)
Пример #11
0
                         fila1=0,
                         fila2=sys.maxint,
                         col1=None,
                         col2=None):
    u"""Filtra el texto dejando solo lo seleccionado.

    La selección es un "rectángulo" marcado por las filas
    y columnas especificadas.

    >>> datos = ("ornitorrinco",) * 10
    >>> list(selecciona_fragmento(datos, 0, 5, 5, 10))
    ['orrin', 'orrin', 'orrin', 'orrin', 'orrin']
    >>> list(selecciona_fragmento(datos, 0, 5, 0, None))
    ['ornitorrinco', 'ornitorrinco', 'ornitorrinco', 'ornitorrinco', 'ornitorrinco']
    """

    lineas = selecciona_lineas(lineas, fila1, fila2)
    resultado = selecciona_columnas(lineas, col1, col2)
    return resultado


def procesa_archivo(archivo, fila1=0, fila2=sys.maxint, col1=None, col2=None):
    u"""Abre un archivo y lo corta según se pida."""

    selecciona_fragmento(open(archivo), fila1, fila2, col1, col2)


if __name__ == "__main__":
    import commandline
    commandline.run_as_main(procesa_archivo)
Пример #12
0
def build_site():
    data = {}
    progress = ProgressBar()
    for theme in progress(theme_list()):
        data[theme] = get_data(theme)
    with open(os.path.join('output', 'v6', 'theme_data.js'), 'wb+') as outf:
        outf.write("var data = " + json.dumps(data, indent=4, ensure_ascii=True, sort_keys=True))

def get_data(theme):
    data = {}
    data['name'] = theme
    readme = utils.get_asset_path('README', [theme])
    if readme:
        data['readme'] = open(readme).read()
    else:
        data['readme'] = 'No readme file available'
    data['chain'] = utils.get_theme_chain(theme)
    data['bootswatch'] = ('bootstrap' in data['chain'] or
        'bootstrap-jinja' in data['chain'] or
        'bootstrap3-jinja' in data['chain'] or
        'bootstrap3' in data['chain']) and \
        'bootstrap3-gradients' not in data['chain']
    data['engine'] = utils.get_template_engine(data['chain'])
    data['chain'] = data['chain'][::-1]
    return data

if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(build_site)
Пример #13
0
        elif m_for_start:
            output += m_for_start.expand(r'\1{% for \2 %}\3') + '\n'
        elif m_for_end:
            output += m_for_end.expand(r'\1{% endfor %}\2') + '\n'

        elif m_namspace:
            output += m_namspace.expand(
                r"\1{% import '\3' as \2 with context %}\4") + '\n'
        elif m_inherit:
            output += m_inherit.expand(r"{% extends '\2' %}\3") + '\n'

        elif m_block_single_line:
            output += m_block_single_line.expand(
                r'\1{% block \2 %}\3{% endblock %}\4') + '\n'
        elif m_block_start:
            output += m_block_start.expand(r'\1{% block \2 %}\3') + '\n'
        elif m_block_end:
            output += m_block_end.expand(r'\1{% endblock %}\2') + '\n'

        else:
            # Doesn't match anything we're going to process, pass though
            output += line

    return output


if __name__ == "__main__":
    import commandline
    colorama.init()
    commandline.run_as_main(jinjify)