Ejemplo n.º 1
0
def connect(factory):
    if config.has_key("ssl") and config["ssl"]:
        if config["ssl"] == "cert":
            log.info("CONNECT: SSL with client cert")

            cli = load_clicert(config["ssl_clicert"])
            ca = load_cacert(config["ssl_cacert"])

            log.info("Using client certificate:\n %s", cli.inspect())

            reactor.connectSSL(config["host"],
                               config["port"],
                               factory,
                               ssl.CertificateOptions(
                                   privateKey=cli.privateKey.original,
                                   certificate=cli.original,
                                   verify=True,
                                   caCerts=(ca.original,)))
        else:
            log.info("CONNECT: SSL default")
            reactor.connectSSL(config["host"],
                               config["port"],
                               factory,
                               ssl.ClientContextFactory())
    else:
        log.info("CONNECT: No SSL")
        reactor.connectTCP("irc.hackint.org",
                           6666,
                           factory)
Ejemplo n.º 2
0
def build_site(ap=None):
    """
    Walk the content tree and build the entire site.
    """

    # Either empty the existing entire site folder
    if not config.has_key('site'):
        print ap.print_help()
        sys.exit()

    if os.path.exists(config['site']):
        # We don't want to just remove the entire folder  - if we do and we're running a
        # server, it will lose it's directory and will have to be re-run
        # by just emptying the folder, the server will automatically find the new site
        for f in os.listdir(config['site']):
            filename = config['site']+"/"+f
            if os.path.isfile(filename):
                os.remove(filename)
            else:
                # We can safely remove entire subtrees of the site folder
                shutil.rmtree(filename)
    else: # or make a new site folder if one doesn't exist
        os.mkdir(config['site'])

    # Copy any static stuff over
    if os.path.exists(config['static']):
        shutil.copytree(config['static'],config['site']+"/"+config['static_dest'])

    # Generate the content
    valid_extensions = config['extensions'].keys()

    # Walk through the content folder (making subdirectories as needed
    # and process each file
    # We'll have to revisit this when we do the posts stuff
    # but for now it works
    for (dir,subs,files) in os.walk(config['content']):
        dest = re.sub(config['content'],config['site'],dir)
        for sub in subs:
            if not os.path.exists(dest+"/"+sub):
                os.mkdir(dest+"/"+sub)
        for f in files:
            (name,ext)=os.path.splitext(f)
            if name[0] != '.' and ext[1:] in valid_extensions:
                result = ps.process_file(dir+"/"+f)
                outfilename=dest+"/"+name+".html"
                outfile = open(outfilename,"w")
                outfile.write(result)
                outfile.close()
            else: # just copy over the file
                shutil.copyfile(dir+"/"+f,dest+"/"+f)
Ejemplo n.º 3
0
    def regplugin(self, mod, name):
        """ register plugin. """

        name = name.lower()
        mod = mod.lower()
        modname = mod + '.' + name

        # see if plugin is in deny
        if name in self.avail:
            rlog(9, 'plugins', '%s already registered' % name)
            return
        if name in self.plugdeny.data:
            rlog(10, 'plugins', '%s.%s in deny .. not loading' % \
(mod, name))
            return 0
        if config.has_key('loadlist') and name not in config[
                'loadlist'] and 'gozerplugs' in modname and name not in self.plugallow.data:
            rlog(9, 'plugins', 'not loading %s.%s' % (mod, name))
            return 0

        # if plugin is already registered unload it
        if self.plugs.has_key(name):
            rlog(10, 'plugins', 'overloading %s plugin with %s version' \
% (name, mod))
            self.unloadnosave(name)

        # create the plugin data dir
        if not os.path.isdir(datadir + os.sep + 'plugs'):
            os.mkdir(datadir + os.sep + 'plugs')
        if not os.path.isdir(datadir + os.sep + 'plugs' + os.sep + name):
            os.mkdir(datadir + os.sep + 'plugs' + os.sep + name)

        # import the plugin
        plug = self.plugimport(mod, name)
        rlog(0, 'plugins', "%s.%s registered" % (mod, name))
        return plug
Ejemplo n.º 4
0
    def regplugin(self, mod, name):

        """ register plugin. """

        name = name.lower()
        mod = mod.lower()
        modname = mod + '.' + name

        # see if plugin is in deny
        if name in self.avail:
            rlog(9, 'plugins', '%s already registered' % name)
            return
        if name in self.plugdeny.data:
            rlog(10, 'plugins', '%s.%s in deny .. not loading' % \
(mod, name))
            return 0
        if config.has_key('loadlist') and name not in config['loadlist'] and 'gozerplugs' in modname and name not in self.plugallow.data:
                rlog(9, 'plugins', 'not loading %s.%s' % (mod, name))
                return 0

        # if plugin is already registered unload it
        if self.plugs.has_key(name):
            rlog(10, 'plugins', 'overloading %s plugin with %s version' \
% (name, mod))
            self.unloadnosave(name)

        # create the plugin data dir
        if not os.path.isdir(datadir + os.sep + 'plugs'):
            os.mkdir(datadir + os.sep + 'plugs')
        if not os.path.isdir(datadir + os.sep + 'plugs' + os.sep + name):
            os.mkdir(datadir + os.sep + 'plugs' + os.sep + name)

        # import the plugin
        plug = self.plugimport(mod, name)
        rlog(0, 'plugins', "%s.%s registered" % (mod, name))
        return plug
Ejemplo n.º 5
0
        urlopener = urllib.FancyURLopener({'http':'http://%s'%phost})
        if not puser_pass:
            urlopener.addheaders = [('User-agent', self.user_agent)]
        else:
            urlopener.addheaders = [('User-agent', self.user_agent),
                                    ('Proxy-authorization', 'Basic ' + puser_pass) ]

        host = unquote(host)
        f = urlopener.open("http://%s%s"%(host,handler), request_body)

        self.verbose = verbose 
        return self.parse_response(f)

# Make initial connection to service, then login as developer
p = UrllibTransport()
if( config.has_key('proxy') ):
    p.set_proxy(config['proxy'])
    server = xmlrpclib.Server(config['url'], allow_none=True, transport=p);
else:
    server = xmlrpclib.Server(config['url'], allow_none=True);
    
connection = server.system.connect();

# hash_hmac('sha256', $timestamp .';'.$domain .';'. $nonce .';'.'user.get', 'remote_api_key');
#h = hmac.new(key, data, digest_module)
#result = h.hexdigest()

#session = server.user.login( config['username'], config['password']);
#session = server.user.login(config['key'], 'localhost.domd', '', 'C7nW83nDw', connection['sessid'], config['username'], config['password']);
session = server.user.login(connection['sessid'],config['username'], config['password']);
sessid = session['sessid'];
Ejemplo n.º 6
0
def download_subtitles(initial_path,
                       user,
                       password,
                       languages,
                       recursive=True):
    '''
    Logins into opensubtitles.org and start the recursive search
    '''
    global config
    global failed_list

    try:
        #if os.path.isfile(config_file):
        with open(config_file) as f:
            config = json.load(f)
    except:
        config = {
            'last_download_date': None,
            'today_download_count': 0,
            'username': '',
            'password': '',
            'languages': ['por', 'pob', 'eng'],
            'initial_path': initial_path
        }

    today = datetime.date.today().strftime("%Y%m%d")
    if config['last_download_date'] != today:
        config['last_download_date'] = today
        config['today_download_count'] = 0

    if user == None:
        user = config['username']
    else:
        config['username'] = user
    if user != None:
        password = config['password']
    else:
        config['password'] = password

    config['languages'] = languages
    config['initial_path'] = initial_path
    if not config.has_key('ignore_previously_failed'):
        config['ignore_previously_failed'] = True
    _save_config()

    if user == None or password == None:
        print '''
        ERROR: You need to provide login info for OpenSubitles. Either:\n
            - Pass user/password
              OR
            - Edit config/config.json to set a fix user/password
        '''
        return False

    if os.path.isfile(failed_list_file):
        with open(failed_list_file) as f:
            failed_list = f.readlines()
            failed_list = [x.strip() for x in failed_list]

    print "Connecting to OpenSubtitles.org..."
    osub = OpenSubtitles()
    time.sleep(0.1)
    for i in range(6):
        try:
            token = osub.login(user, password)

            if token == None:
                print "---> Error. Invalid username/password. Please check your login information with OpenSubtitles.org"
                return False
            else:
                break
        except:
            time.sleep(1)
            if i < 5:
                print "---> Connection trial #%d failed" % (i + 1)
            else:
                print "ERROR: Could not connect to OpenSubtitle.org"
                return False

    _download_subtitles_at_path(initial_path, osub, languages, recursive)

    osub.logout()

    remaining_downloads = MAX_DOWNLOADS_PER_DAY - config['today_download_count']

    print "Done!"
    print "%d subtitles downloaded at this session" % (success_downloads)
    print "%d downloads failed at this session" % (failed_downloads)
    print "You can still download %d subtitles today from OpenSubtitles.org (Max per day:%d)" % (
        remaining_downloads, MAX_DOWNLOADS_PER_DAY)
    print ""
    print "%d video files not considered during this search\n(Either already had subtitle or had failed in a previous search)" % (
        skipped_files)
    print "(If you want to try downloading them again, please remove their names from the following file, or delete this file)"
    print failed_list_file

    #$with open(failed_list_file, 'w') as f:
    #    for item in failed_list:
    #        f.write("%s\n" % (item))
    return True
Ejemplo n.º 7
0
            urlopener.addheaders = [('User-agent', self.user_agent)]
        else:
            urlopener.addheaders = [('User-agent', self.user_agent),
                                    ('Proxy-authorization',
                                     'Basic ' + puser_pass)]

        host = unquote(host)
        f = urlopener.open("http://%s%s" % (host, handler), request_body)

        self.verbose = verbose
        return self.parse_response(f)


# Make initial connection to service, then login as developer
p = UrllibTransport()
if (config.has_key('proxy')):
    p.set_proxy(config['proxy'])
    server = xmlrpclib.Server(config['url'], allow_none=True, transport=p)
else:
    server = xmlrpclib.Server(config['url'], allow_none=True)

connection = server.system.connect()

# hash_hmac('sha256', $timestamp .';'.$domain .';'. $nonce .';'.'user.get', 'remote_api_key');
#h = hmac.new(key, data, digest_module)
#result = h.hexdigest()

#session = server.user.login( config['username'], config['password']);
#session = server.user.login(config['key'], 'localhost.domd', '', 'C7nW83nDw', connection['sessid'], config['username'], config['password']);
session = server.user.login(connection['sessid'], config['username'],
                            config['password'])