コード例 #1
0
ファイル: autosubd.py プロジェクト: falconpy/autosubd
def search_sub(filename):
	f=File(path+filename)
	content = [{'sublanguageid':language,'moviebytesize':f.size ,'moviehash':f.get_hash()}]
	try:
		datarcv = Os1.search_subs(content)
		downlink = datarcv['data'][0]['SubDownloadLink']

		#Downloading zip file
		urllib.urlretrieve(downlink, 'subtemp.gz')

		#Unzip de subtitle file in directory
		inF = gzip.GzipFile('subtemp.gz', 'rb')
		s = inF.read()
		inF.close()
		filenamesrt = filename[0:len(filename)-4] + '.' + language_ext + '.srt'
		outF = file(path+filenamesrt, 'wb')
		outF.write(s)
		outF.close()
		print fn + ' -> ' + bcolors.OKGREEN + 'Download OK' + bcolors.ENDC
	except:
		print fn + ' -> ' + bcolors.WARNING + 'No subtitle found' + bcolors.ENDC
コード例 #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--discover", action="append", nargs="+", default=[])
    parser.add_argument("--modules", action="append", nargs="+", default=[])
    parser.add_argument("--exclude", action="append", nargs="+", default=[])
    parser.add_argument("--interlink", action="append", default=[])
    parser.add_argument("--rst", default=None)
    parser.add_argument("--html", default=None)
    parser.add_argument("--skip-failed", action="store_true")
    parser.add_argument("--theme", default=None)
    parser.add_argument("--title", default=None)
    make_switch(parser, "inheritance", False)
    make_switch(parser, "mro", True)
    make_switch(parser, "overrides", True)
    args = parser.parse_args()
    args.discover = flatten(args.discover)
    args.modules = flatten(args.modules)
    args.exclude = flatten(args.exclude)
    #output_dir = File(args.output)
    #output_dir.create_folder(ignore_existing=True, recursive=True)
    
    if not (args.modules or args.discover):
        print "Error: need one of --modules or --discover."
        print "Use --help for more info."
        sys.exit(1)
    
    module_names = set()
    for folder_name in args.discover:
        folder = File(folder_name)
        # Add the folder to the path so we can import things from it
        sys.path.insert(0, folder.path)
        print "Discovering packages and modules in %r..." % folder.path
        for thing in folder.recurse(lambda f:
                YIELD if f.name.endswith(".py") and not f.name.startswith("__") and f != folder.child("setup.py") else 
                True if f.child("__init__.py").exists else
                RECURSE if f == folder else SKIP):
            name = thing.get_path(relative_to=folder, separator=".")
            # Strip off trailing ".py" for modules
            if thing.is_file:
                name = name[:-3]
            print "Discovered package/module %s" % name
            module_names.add(name)
    for name in args.modules:
        print "Including module %s on request" % name
        module_names.add(name)
    
    exclude = set(args.exclude)
    for name in set(module_names):
        current = name
        # See if the module or any of its parent packages are in the exclude
        # list
        while current:
            if current in exclude:
                print "Excluding %s on request" % name
                module_names.discard(name)
                break
            current, _, _ = current.rpartition(".")
    
    modules = set()
    for module_name in module_names:
        print "Importing %s" % module_name
        try:
            module = importlib.import_module(module_name)
        except:
            if args.skip_failed:
                print "IMPORT FAILED, ignoring."
            else:
                raise
        else:
            modules.add(module)
    
    modules = sorted(modules, key=lambda m: m.__name__)
    print "Final list of modules to document: %s" % ", ".join(m.__name__ for m in modules)
    
    if args.rst:
        rst = File(args.rst)
        rst.delete(ignore_missing=True)
    else:
        rst = create_temporary_folder(delete_on_exit=True)
    rst.create_folder(ignore_existing=True, recursive=True)
    module_dir = rst.child("modules")
    module_dir.create_folder(True, True)
    
    # conf = "project = {0!r}\n".format("Test Project")
    with rst.child("conf.py").open("wb") as f:
        extensions = []
        
        if args.title:
            f.write("project = {0!r}\n".format(args.title))
        if args.theme:
            f.write("html_theme = {0!r}\n".format(args.theme))
        
        if args.interlink:
            extensions.append("sphinx.ext.intersphinx")
            intersphinx_mapping = {}
            for url in args.interlink:
                # We're not supporting explicit keys for now, so just use the
                # URL to make sure we've got a unique one. Perhaps in the
                # future I'll add something like --named-interlink <name> <url>
                # to support qualified interlinking.
                intersphinx_mapping[url] = (url, None)
            f.write("intersphinx_mapping = {0!r}\n".format(intersphinx_mapping))
            f.write("intersphinx_cache_limit = 0\n")
        
        f.write("extensions = {0!r}\n".format(extensions))
    
    with rst.child("contents.rst").open("wb") as contents:
        contents.write(".. toctree::\n")
        for module in modules:
            contents.write("   modules/{0}.rst\n".format(module.__name__))
    
    for module in modules:
        with module_dir.child(module.__name__ + ".rst").open("wb") as m:
            display_module(module, m, 0, args)
    
    if args.html:
        html = File(args.html)
        html.delete(ignore_missing=True)
        html.create_folder(recursive=True)
        with rst.as_working:
            subprocess.check_output(["sphinx-build", "-b", "html",
                                     rst.path, html.path])
        # Include a simple index.html that redirects to py-modindex.html. I'll
        # likely make the index page's content configurable at some point.
        html.child("index.html").write("""
        <html>
            <head>
                <meta http-equiv="refresh" content="0; url=py-modindex.html"/>
            </head>
            <body>
                <a href="py-modindex.html">py-modindex.html</a>
            </body>
        </html>""")
コード例 #3
0
import argparse
from fileutils import File, YIELD, SKIP, RECURSE, create_temporary_folder
import importlib
import inspect
from singledispatch import singledispatch
import types
import pydoc
from collections import namedtuple
import sys
import subprocess

FILE = File(__file__)
MethodWrapper = namedtuple("MethodWrapper", ["function"])
PropertyWrapper = namedtuple("PropertyWrapper", ["name", "prop"])

def make_switch(parser, name, default):
    parser.add_argument("--" + name, action="store_const", dest=name.replace("-", "_"), const=True, default=default)
    parser.add_argument("--no-" + name, action="store_const", dest=name.replace("-", "_"), const=False, default=default)


def flatten(list):
    return [v for l in list for v in l]


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--discover", action="append", nargs="+", default=[])
    parser.add_argument("--modules", action="append", nargs="+", default=[])
    parser.add_argument("--exclude", action="append", nargs="+", default=[])
    parser.add_argument("--interlink", action="append", default=[])