Ejemplo n.º 1
0
def start():
    global __INITIALIZED__, scheduler_started

    if __INITIALIZED__:

        try:
            # Crons and scheduled jobs go here
            # testInterval = IntervalTrigger(weeks=0, days=0, hours=0, minutes=2, seconds=0, start_date=None, end_date=None, timezone=None)
            # testCron = CronTrigger(year=None, month=None, day=None, week=None, day_of_week=None, hour=None, minute='*/2', second=None, start_date=None, end_date=None, timezone=None)
            # SCHED.add_job(formatter.schedulerTest, testCron)
            if GIT_ENABLED and GIT_INTERVAL != 0:
                gitInterval = IntervalTrigger(weeks=0,
                                              days=0,
                                              hours=GIT_INTERVAL,
                                              minutes=0,
                                              seconds=0,
                                              start_date=None,
                                              end_date=None,
                                              timezone=None)
                SCHED.add_job(versioncheck.checkGithub, gitInterval)
            SCHED.start()
            for job in SCHED.get_jobs():
                logger.info("Job scheduled: %s" % job)
            scheduler_started = True
        except Exception, e:
            logger.error("Can't start scheduled job(s): %s" % e)
Ejemplo n.º 2
0
def ajaxMSG(status, status_msg):
    if status == 'success':
        logger.info(status_msg)
    elif status == 'failure':
        logger.warn(status_msg)

    return status, status_msg
Ejemplo n.º 3
0
def checkGithub():
    cherrystrap.COMMITS_BEHIND = 0

    # Get the latest version available from github
    logger.info('Retrieving latest version information from GitHub')
    url = 'https://api.github.com/repos/%s/%s/commits/%s' % (cherrystrap.GIT_USER, cherrystrap.GIT_REPO, cherrystrap.GIT_BRANCH)
    try:
        result = urllib2.urlopen(url).read()
        version = json.JSONDecoder().decode(result)
    except Exception, e:
        logger.warn('Could not get the latest version from GitHub. Are you running a local development version?: %s' % e)
        return cherrystrap.GIT_LOCAL
Ejemplo n.º 4
0
def bulkDeleteWorklogs(issue_list=None):
    status, msg = '', ''

    consumer, client = backend.stored_oauth()

    num_issues = 0
    num_worklogs = 0
    for issue in issue_list:
        num_issues += 1
        data_url = os.path.join(jiraappy.JIRA_BASE_URL,
                                'rest/api/2/issue/' + issue + '/worklog')
        try:
            resp, content = client.request(data_url, "GET")
            if resp['status'] != '200':
                logger.warn("Request for %s failed with status code %s - %s" (
                    data_url, resp['status'], content))
            else:
                resp_dict = json.loads(content)
                num_results = resp_dict['total']
                if num_results != 0:
                    for result in range(0, num_results):
                        worklog_id = resp_dict['worklogs'][result]['id']
                        data_url = os.path.join(
                            jiraappy.JIRA_BASE_URL,
                            'rest/api/2/issue/' + issue + '/worklog/' +
                            worklog_id + '?adjustEstimate=leave')
                        try:
                            resp, content = client.request(data_url, "DELETE")
                            if resp['status'] != '204':
                                logger.warn(
                                    "Request for %s failed with status code %s - %s" (
                                        data_url, resp['status'], content))
                            else:
                                num_worklogs += 1
                                logger.info(
                                    "Worklog ID %s for issue %s has been deleted"
                                    % (worklog_id, issue))
                        except:
                            logger.warn("Could not connect to %s" % data_url)
                    status, msg = backend.ajaxMSG(
                        'success',
                        '%d worklog(s) have been deleted for %d issues' %
                        (num_worklogs, num_issues))
                else:
                    logger.info("No worklogs found for issue %s" % issue)
        except:
            logger.warn("Could not connect to %s" % data_url)

    return status, msg
Ejemplo n.º 5
0
    def twitterStep2(self, key):
        cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
        message={}

        result = twitter_notifier._get_credentials(key)
        logger.info(u"result: "+str(result))

        if result:
            message['status'] = 'success'
            message['message'] = 'Key verification successful'
            return "Key verification successful"
        else:
            message['status'] = 'danger'
            message['message'] = 'Unable to verify key'
            return "Unable to verify key"
Ejemplo n.º 6
0
    def _send_tweet(self, message=None):

        username=self.consumer_key
        password=self.consumer_secret
        access_token_key=orielpy.TWITTER_TOKEN
        access_token_secret=orielpy.TWITTER_SECRET

        logger.info(u"Sending tweet: "+message)

        api = twitter.Api(username, password, access_token_key, access_token_secret)

        try:
            api.PostUpdate(message)
        except Exception, e:
            logger.error(u"Error Sending Tweet: %s" %e)
            return False
Ejemplo n.º 7
0
def import_XML(full_url, source, plaintext, media_type):
    hdr = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'}

    try:
        myDB = database.SQLite_DBConnection()
        pass
    except:
        logger.info("There was a SQLite connection error.")

    req = urllib2.Request(full_url, headers=hdr)
    xml_file = urllib2.urlopen(req)
    xml_data = xml_file.read()
    xml_file.close()
    xml_root = etree.fromstring(xml_data)
    item = xml_root.findall('channel/item')
    
    if source=="Billboard":
        for entry in item:
            pubDate = entry.findtext('pubDate')
            link = entry.findtext('link')
            title = entry.findtext('title')
            description = entry.findtext('description')

            title_split = title.split(':')
            rank = int(title_split[0])
            description_split = description.split(' by ')
            album = description_split[0]
            description_split2 = description_split[1].split(' ranks ')
            artist_temp = description_split2[0].split(' Featuring ')
            artist = artist_temp[0]

            myDB.action("INSERT INTO billboard_music_releases (billboard_nr_genre, billboard_nr_artist, \
                billboard_nr_album, billboard_nr_rank, billboard_nr_link, billboard_nr_release, billboard_nr_timestamp) \
                VALUES (?, ?, ?, ?, ?, ?, ?)", (plaintext, artist, album, rank, link, media_type, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
        
    elif source=="Rotten Tomatoes":
        for entry in item:
            pubDate = entry.findtext('pubDate')
            link = entry.findtext('link')
            title = entry.findtext('title').split(" ", 1)[1]
            percent = entry.findtext('title').split(" ", 1)[0]
            description = entry.findtext('description')


            myDB.action("INSERT INTO rottentomatoes_movies (rotten_genre, rotten_title, rotten_link, rotten_description, rotten_percent, rotten_timestamp) \
                            VALUES(?, ?, ?, ?, ?, ?)", (plaintext, title, link, description, percent, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
Ejemplo n.º 8
0
def check_oauth():
    consumer = oauth.Consumer(jiraappy.CONSUMER_KEY, jiraappy.CONSUMER_SECRET)
    accessToken = oauth.Token(jiraappy.JIRA_OAUTH_TOKEN, jiraappy.JIRA_OAUTH_SECRET)
    client = oauth.Client(consumer, accessToken)
    client.set_signature_method(SignatureMethod_RSA_SHA1())

    data_url = os.path.join(jiraappy.JIRA_BASE_URL, 'rest/api/2/myself')

    resp, content = client.request(data_url, "GET")
    if resp['status'] != '200':
        jiraappy.JIRA_LOGIN_STATUS = None
        jiraappy.JIRA_LOGIN_USER = None
        logger.warn("OAuth credentials missing or invalid")
    else:
        resp_dict = json.loads(content)
        jiraappy.JIRA_LOGIN_STATUS = True
        jiraappy.JIRA_LOGIN_USER = resp_dict['name']
        logger.info("JIRA user %s verified login" % resp_dict['name'])
Ejemplo n.º 9
0
def scrape_playlists():
    try:
        myDB = database.SQLite_DBConnection()
        pass
    except:
        logger.info("There was a SQLite connection error while scraping playlists.")

    myDB.action("DELETE FROM billboard_music_releases")
    myDB.action("DELETE FROM rottentomatoes_movies")

    enabled_lists = myDB.select("SELECT * FROM available_options WHERE enabled='Yes' ORDER BY plaintext ASC")
    if enabled_lists:
        for playlist in enabled_lists:
            if playlist['source'] == 'Billboard':
                full_url = "http://www.billboard.com/rss/charts/"+playlist['sublink']
            elif playlist['source'] == 'Rotten Tomatoes':
                full_url = "http://www.rottentomatoes.com/syndication/rss/"+playlist['sublink']
            import_XML(full_url, playlist['source'], playlist['plaintext'], playlist['type'])
Ejemplo n.º 10
0
    def _get_authorization(self):

        signature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1() #@UnusedVariable
        oauth_consumer             = oauth.Consumer(key=self.consumer_key, secret=self.consumer_secret)
        oauth_client               = oauth.Client(oauth_consumer)

        logger.info('Requesting temp token from Twitter')

        resp, content = oauth_client.request(self.REQUEST_TOKEN_URL, 'GET')

        if resp['status'] != '200':
            logger.info('Invalid respond from Twitter requesting temp token: %s' % resp['status'])
        else:
            request_token = dict(parse_qsl(content))

            orielpy.TWITTER_TOKEN = request_token['oauth_token']
            orielpy.TWITTER_SECRET = request_token['oauth_token_secret']

            return self.AUTHORIZATION_URL+"?oauth_token="+ request_token['oauth_token']
Ejemplo n.º 11
0
def start():
    global __INITIALIZED__, scheduler_started

    if __INITIALIZED__:

        try:
            # Crons and scheduled jobs go here
            # testInterval = IntervalTrigger(weeks=0, days=0, hours=0, minutes=2, seconds=0, start_date=None, end_date=None, timezone=None)
            # testCron = CronTrigger(year=None, month=None, day=None, week=None, day_of_week=None, hour=None, minute='*/2', second=None, start_date=None, end_date=None, timezone=None)
            # SCHED.add_job(formatter.schedulerTest, testCron)
            if GIT_ENABLED and GIT_INTERVAL != 0:
                gitInterval = IntervalTrigger(weeks=0, days=0, hours=GIT_INTERVAL, minutes=0, seconds=0, start_date=None, end_date=None, timezone=None)
                SCHED.add_job(versioncheck.checkGithub, gitInterval)
            SCHED.start()
            for job in SCHED.get_jobs():
                logger.info("Job scheduled: %s" % job)
            scheduler_started = True
        except Exception, e:
            logger.error("Can't start scheduled job(s): %s" % e)
Ejemplo n.º 12
0
def save_playlist(playlist_name):
    try:
        myDB = database.SQLite_DBConnection()
        pass
    except:
        logger.info("There was a SQLite connection error.")
        return serve_template(templatename="config.html")

    PLDIR = os.path.join(cherrystrap.DATADIR, 'playlists')
    if not os.path.exists(PLDIR):
        try:
            os.makedirs(PLDIR)
        except OSError:
            logger.error('Could not create playlist directory. Check permissions of: ' + cherrystrap.DATADIR)
    
    filename = datetime.datetime.now().strftime('%Y-%m-%d')+" - "+playlist_name
    xbmc_playlist = os.path.join(cherrystrap.DATADIR, 'playlists', filename+'_XBMC.m3u')
    win_playlist = os.path.join(cherrystrap.DATADIR, 'playlists', filename+'_Win.m3u')
    mac_playlist = os.path.join(cherrystrap.DATADIR, 'playlists', filename+'_Mac.m3u')

    xbmc = open(xbmc_playlist,'w')
    pl_db = myDB.select("SELECT * FROM generated_playlist")
    if pl_db:
        for item in pl_db:
            xbmc.write(item['filepath'].encode('utf-8')+'\n')
    xbmc.close()

    win = open(win_playlist,'w')
    pl_db = myDB.select("SELECT * FROM generated_playlist")
    if pl_db:
        for item in pl_db:
            songpath = item['filepath'].replace('smb:','').replace("/","\\")
            win.write(songpath.encode('utf-8')+'\n')
    win.close()

    mac = open(mac_playlist,'w')
    pl_db = myDB.select("SELECT * FROM generated_playlist")
    if pl_db:
        for item in pl_db:
            songpath = item['filepath'].replace('smb://MAXPOWER/','/Volumes/')
            mac.write(songpath.encode('utf-8')+'\n')
    mac.close()
Ejemplo n.º 13
0
    def generateUsers(self):
        for root, dirs, files in os.walk(os.path.join(cherrystrap.DATADIR,'cache')):
            for f in files:
                os.unlink(os.path.join(root, f))
            for d in dirs:
                shutil.rmtree(os.path.join(root, d))
        try:
            myDB = database.DBConnection()
            pass
        except:
            logger.info("There was a MySQL connection error.  Please check your Vanilla MySQL connection credentials")
            return serve_template(templatename="index.html")

        JSONDIR = os.path.join(cherrystrap.DATADIR,'cache','users')
        if not os.path.exists(JSONDIR):
            try:
                os.makedirs(JSONDIR)
            except OSError:
                logger.error('Could not create user director. Check permissions of: ' + cherrystrap.DATADIR)
        
        userInfo=[]
        userCount = 0
        support_users = ([support_user.strip() for support_user in cherrystrap.VANILLA_SUPPORT.split(',')])
        users = myDB.select("SELECT * FROM %s" % cherrystrap.VANILLA_DB+'.GDN_User')
        for user in users:
            userCount += 1
            if user['Name'] in support_users:
                user_state = "support"
            else:
                user_state = "user"
            userInfo = {
                "name": user['Name'],
                "email": user['Email'],
                "title": "",
                "created_at": user['DateInserted'].strftime('%Y-%m-%dT%H:%M:%SZ'),
                "state": user_state,
                "password": "******"
                }
            OUTDIR = os.path.join(JSONDIR,str(userCount)+'.json')
            with open(OUTDIR, 'w') as outfile:
                json.dump(userInfo, outfile)
Ejemplo n.º 14
0
    def configUpdate(self, server_name="Vanilla2Tender", http_host='0.0.0.0', http_user=None, http_port=7949, http_pass=None, http_look=None, launch_browser=0, logdir=None, 
        vanilla_host=None, vanilla_port=None, vanilla_user=None, vanilla_password=None, vanilla_db=None, vanilla_support=None):

        cherrystrap.SERVER_NAME = server_name
        cherrystrap.HTTP_HOST = http_host
        cherrystrap.HTTP_PORT = http_port
        cherrystrap.HTTP_USER = http_user
        cherrystrap.HTTP_PASS = http_pass
        cherrystrap.HTTP_LOOK = http_look
        cherrystrap.LAUNCH_BROWSER = launch_browser
        cherrystrap.LOGDIR = logdir

        cherrystrap.VANILLA_HOST = vanilla_host
        cherrystrap.VANILLA_PORT = vanilla_port
        cherrystrap.VANILLA_USER = vanilla_user
        cherrystrap.VANILLA_PASSWORD = vanilla_password
        cherrystrap.VANILLA_DB = vanilla_db
        cherrystrap.VANILLA_SUPPORT = vanilla_support

        cherrystrap.config_write()
        logger.info("Configuration saved successfully")
Ejemplo n.º 15
0
    def action(self, query, args=None):

        with self.connection:
            self.cursor = self.connection.cursor(MySQLdb.cursors.DictCursor)

            if query == None:
                return

            sqlResult = None

            try:
                if args == None:
                    self.cursor.execute(query)
                else:
                    self.cursor.execute(query,args)
                self.connection.commit()
            except MySQLdb.IntegrityError:
                logger.info("failed to make transaction")

            sqlResult = self.cursor
            return sqlResult
Ejemplo n.º 16
0
    def action(self, query, args=None):
        
        with self.connection:
            self.cursor = self.connection.cursor(MySQLdb.cursors.DictCursor)

            if query == None:
                return

            sqlResult = None

            try:
                if args == None:
                    self.cursor.execute(query)
                else:
                    self.cursor.execute(query,args)
                self.connection.commit()
            except MySQLdb.IntegrityError:
                logger.info("failed to make transaction")

            sqlResult = self.cursor
            return sqlResult
Ejemplo n.º 17
0
    def generateCategories(self):
        try:
            myDB = database.DBConnection()
            pass
        except:
            logger.info("There was a MySQL connection error.  Please check your Vanilla MySQL connection credentials")
            return serve_template(templatename="index.html")

        JSONDIR = os.path.join(cherrystrap.DATADIR,'cache','categories')
        if not os.path.exists(JSONDIR):
            try:
                os.makedirs(JSONDIR)
            except OSError:
                logger.error('Could not create user director. Check permissions of: ' + cherrystrap.DATADIR)
        
        categoryInfo=[]
        categoryCount = 0
        categories = myDB.select("SELECT * FROM %s" % cherrystrap.VANILLA_DB+'.GDN_Category')
        for category in categories:
            if category['Name'] != 'Root':
                categoryCount += 1
                categoryID = category['CategoryID']
                
                CATDIR = os.path.join(cherrystrap.DATADIR,'cache','categories',str(categoryID))
                if not os.path.exists(CATDIR):
                    try:
                        os.makedirs(CATDIR)
                    except OSError:
                        logger.error('Could not create user director. Check permissions of: ' + cherrystrap.DATADIR)

                categoryInfo = {
                    "name": category['Name'],
                    "summary": category['Description']
                    }
                OUTDIR = os.path.join(JSONDIR,str(categoryID)+'.json')
                with open(OUTDIR, 'w') as outfile:
                    json.dump(categoryInfo, outfile)
Ejemplo n.º 18
0
def bulkDeleteWorklogs(issue_list=None):
    status, msg = '', ''

    consumer, client = backend.stored_oauth()

    num_issues = 0
    num_worklogs = 0
    for issue in issue_list:
        num_issues+=1
        data_url = os.path.join(jiraappy.JIRA_BASE_URL, 'rest/api/2/issue/'+issue+'/worklog')
        try:
            resp, content = client.request(data_url, "GET")
            if resp['status'] != '200':
                logger.warn("Request for %s failed with status code %s - %s" (data_url, resp['status'], content))
            else:
                resp_dict = json.loads(content)
                num_results = resp_dict['total']
                if num_results != 0:
                    for result in range(0, num_results):
                        worklog_id = resp_dict['worklogs'][result]['id']
                        data_url = os.path.join(jiraappy.JIRA_BASE_URL, 'rest/api/2/issue/'+issue+'/worklog/'+worklog_id+'?adjustEstimate=leave')
                        try:
                            resp, content = client.request(data_url, "DELETE")
                            if resp['status'] != '204':
                                logger.warn("Request for %s failed with status code %s - %s" (data_url, resp['status'], content))
                            else:
                                num_worklogs+=1
                                logger.info("Worklog ID %s for issue %s has been deleted" % (worklog_id, issue))
                        except:
                            logger.warn("Could not connect to %s" % data_url)
                    status, msg = backend.ajaxMSG('success', '%d worklog(s) have been deleted for %d issues' % (num_worklogs, num_issues))
                else:
                    logger.info("No worklogs found for issue %s" % issue)
        except:
            logger.warn("Could not connect to %s" % data_url)

    return status, msg
Ejemplo n.º 19
0
def shutdown(restart=False):
    config_write()
    logger.info('cherrystrap is shutting down ...')
    cherrypy.engine.exit()

    SCHED.shutdown(wait=True)

    if PIDFILE :
        logger.info('Removing pidfile %s' % PIDFILE)
        os.remove(PIDFILE)

    if restart:
        logger.info('cherrystrap is restarting ...')
        popen_list = [sys.executable, FULL_PATH]
        popen_list += ARGS
        if '--nolaunch' not in popen_list:
            popen_list += ['--nolaunch']
            logger.info('Restarting cherrystrap with ' + str(popen_list))
        subprocess.Popen(popen_list, cwd=os.getcwd())

    os._exit(0)
Ejemplo n.º 20
0
def initialize(options={}):

    https_enabled = options['https_enabled']
    https_cert = options['https_cert']
    https_key = options['https_key']

    if https_enabled:
        # If either the HTTPS certificate or key do not exist, try to make
        # self-signed ones.
        if not (https_cert and os.path.exists(https_cert)) or not (https_key and os.path.exists(https_key)):
            if not create_https_certificates(https_cert, https_key):
                logger.warn("Unable to create certificate and key. Disabling " \
                    "HTTPS")
                https_enabled = False

        if not (os.path.exists(https_cert) and os.path.exists(https_key)):
            logger.warn("Disabled HTTPS because of missing certificate and " \
                "key.")
            https_enabled = False

    options_dict = {
        'log.screen':           False,
        'server.thread_pool':   10,
        'server.socket_port':   int(options['http_port']),
        'server.socket_host':   str(options['http_host']),
        'engine.autoreload.on': False,
        }

    if https_enabled:
        options_dict['server.ssl_certificate'] = https_cert
        options_dict['server.ssl_private_key'] = https_key
        protocol = "https"
    else:
        protocol = "http"

    logger.info("Starting %s on %s://%s:%d/" % (cherrystrap.APP_NAME, protocol,
        options['http_host'], options['http_port']))

    cherrypy.config.update(options_dict)

    webConf = {
        '/': {
            'tools.staticdir.root': os.path.join(cherrystrap.PROG_DIR, 'static')
        },
        '/interfaces':{
            'tools.staticdir.on': True,
            'tools.staticdir.dir': "interfaces"
        },
        '/images':{
            'tools.staticdir.on': True,
            'tools.staticdir.dir': "images"
        },
        '/css':{
            'tools.staticdir.on': True,
            'tools.staticdir.dir': "css"
        },
        '/js':{
            'tools.staticdir.on': True,
            'tools.staticdir.dir': "js"
        },
        '/fonts':{
            'tools.staticdir.on': True,
            'tools.staticdir.dir': "fonts"
        },
        '/favicon.ico':{
            'tools.staticfile.on': True,
            'tools.staticfile.filename': os.path.join(cherrystrap.PROG_DIR, 'static/images/favicon.ico')
        }
    }

    # Prevent time-outs
    cherrypy.engine.timeout_monitor.unsubscribe()
    cherrypy.tree.mount(WebInterface(), options['http_root'], config = webConf)

    # Load API endpoints
    cherrypy.tree.mount(apiServe.settings(), cherrystrap.HTTP_ROOT+'/api/v1/settings',
        {'/': {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}})
    cherrypy.tree.mount(apiServe.log(), cherrystrap.HTTP_ROOT+'/api/v1/log',
        {'/': {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}})

    cherrypy.engine.autoreload.subscribe()

    try:
        cherrypy.process.servers.check_port(options['http_host'], options['http_port'])
        cherrypy.server.start()
        #cherrypy.engine.start() is good for dev mode, but breaks --daemon
    except IOError:
        print 'Failed to start on port: %i. Is something else running?' % (options['http_port'])
        sys.exit(0)

    cherrypy.server.wait()
Ejemplo n.º 21
0
                % e)
        #================================================================

        # Initialize the database
        try:
            createDb(DATABASE_TYPE, DATADIR, APP_NAME, MYSQL_HOST, MYSQL_PORT,
                     MYSQL_USER, MYSQL_PASS)
        except Exception, e:
            logger.error("Error initializing the database: %s" % e)

        # Disable SSL verification for systems where SSL is broken
        if not VERIFY_SSL:
            try:
                import ssl
                ssl._create_default_https_context = ssl._create_unverified_context
                logger.info("SSL verification disabled per user preferences")
            except Exception, e:
                logger.warn(
                    "There was an error disabling SSL verification: %s" % s)
                pass

        # Get the currently installed version. Returns None, 'win32' or the git
        # hash.
        GIT_LOCAL, GIT_BRANCH = versioncheck.getVersion()

        # Write current version to a file, so we know which version did work.
        # This allows one to restore to that version. The idea is that if we
        # arrive here, most parts of the app seem to work.
        if GIT_LOCAL:
            version_lock_file = os.path.join(DATADIR, "version.lock")
Ejemplo n.º 22
0
        except Exception, e:
            logger.warn("Could not connect to SQLite database: %s" % e)

        #===============================================================
        # Import a schema injection system per your  app's __init__.py
        try:
            from jiraappy import injectDbSchema
            injection = injectDbSchema()
            for table, schema in injection.items():
                c.execute('CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY)' % table)
                for columnName, columnFormat in schema.items():
                    try:
                        c.execute('SELECT %s from %s' % (columnName, table))
                    except sqlite3.OperationalError:
                        c.execute('ALTER TABLE %s ADD COLUMN %s %s' % (table, columnName, columnFormat))
                        logger.info('Column %s created in table %s' % (columnName, table))
        except Exception, e:
            logger.warn("There was a problem initializing SQLite database schema: %s" % e)
        #===============================================================

        conn.commit()
        c.close()

    elif DATABASE_TYPE == "mysql":
        try:
            import MySQLdb
            filterwarnings('ignore', category = MySQLdb.Warning)
        except ImportError:
            logger.warn("The MySQLdb module is missing. Install this " \
                "module to enable MySQL. Please revert to SQLite.")
Ejemplo n.º 23
0
def update():
    if cherrystrap.INSTALL_TYPE == 'win':
        logger.info('Windows .exe updating not supported yet.')

    elif cherrystrap.INSTALL_TYPE == 'git':
        output, err = runGit('pull origin ' + cherrystrap.GIT_BRANCH)

        if not output:
            logger.error('Couldn\'t download latest version')

        for line in output.split('\n'):

            if 'Already up-to-date.' in line:
                logger.info('No update available, not updating')
                logger.info('Output: ' + str(output))
            elif line.endswith('Aborting.'):
                logger.error('Unable to update from git: ' + line)
                logger.info('Output: ' + str(output))

    else:
        tar_download_url = 'https://github.com/%s/%s/tarball/%s' % (cherrystrap.GIT_USER, cherrystrap.GIT_REPO, cherrystrap.GIT_BRANCH)
        update_dir = os.path.join(cherrystrap.PROG_DIR, 'update')
        version_path = os.path.join(cherrystrap.PROG_DIR, 'version.txt')

        logger.info('Downloading update from: ' + tar_download_url)
        data = urllib2.urlopen(tar_download_url)

        if not data:
            logger.error("Unable to retrieve new version from '%s', can't update", tar_download_url)
            return

        download_name = cherrystrap.GIT_BRANCH + '-github'
        tar_download_path = os.path.join(cherrystrap.PROG_DIR, download_name)

        # Save tar to disk
        with open(tar_download_path, 'wb') as f:
            f.write(data)

        # Extract the tar to update folder
        logger.info('Extracting file: ' + tar_download_path)
        tar = tarfile.open(tar_download_path)
        tar.extractall(update_dir)
        tar.close()

        # Delete the tar.gz
        logger.info('Deleting file: ' + tar_download_path)
        os.remove(tar_download_path)

        # Find update dir name
        update_dir_contents = [x for x in os.listdir(update_dir) if os.path.isdir(os.path.join(update_dir, x))]
        if len(update_dir_contents) != 1:
            logger.error("Invalid update data, update failed: " + str(update_dir_contents))
            return
        content_dir = os.path.join(update_dir, update_dir_contents[0])

        # walk temp folder and move files to main folder
        for dirname, dirnames, filenames in os.walk(content_dir):
            dirname = dirname[len(content_dir) + 1:]
            for curfile in filenames:
                old_path = os.path.join(content_dir, dirname, curfile)
                new_path = os.path.join(cherrystrap.PROG_DIR, dirname, curfile)

                if os.path.isfile(new_path):
                    os.remove(new_path)
                os.renames(old_path, new_path)

        # Update version.txt
        try:
            with open(version_path, 'w') as f:
                f.write(str(cherrystrap.GIT_UPSTREAM))
        except IOError as e:
            logger.error(
                "Unable to write current version to version.txt, update not complete: %s",
                e
            )
            return
Ejemplo n.º 24
0
def main():

    # rename this thread
    threading.currentThread().name = "MAIN"

    # Set paths
    if hasattr(sys, 'frozen'):
        cherrystrap.FULL_PATH = os.path.abspath(sys.executable)
    else:
        cherrystrap.FULL_PATH = os.path.abspath(__file__)

    cherrystrap.PROG_DIR = os.path.dirname(cherrystrap.FULL_PATH)
    cherrystrap.ARGS = sys.argv[1:]

    cherrystrap.SYS_ENCODING = None

    try:
        locale.setlocale(locale.LC_ALL, "")
        cherrystrap.SYS_ENCODING = locale.getpreferredencoding()
    except (locale.Error, IOError):
        pass

    # for OSes that are poorly configured I'll just force UTF-8
    if not cherrystrap.SYS_ENCODING or cherrystrap.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
        cherrystrap.SYS_ENCODING = 'UTF-8'

    # Set arguments
    from optparse import OptionParser

    p = OptionParser()
    p.add_option('-d', '--daemon', action = "store_true",
                 dest = 'daemon', help = "Run the server as a daemon")
    p.add_option('-q', '--quiet', action = "store_true",
                 dest = 'quiet', help = "Don't log to console")
    p.add_option('--debug', action="store_true",
                 dest = 'debug', help = "Show debuglog messages")
    p.add_option('--nolaunch', action = "store_true",
                 dest = 'nolaunch', help="Don't start browser")
    p.add_option('--port',
                 dest = 'port', default = None,
                 help = "Force webinterface to listen on this port")
    p.add_option('--datadir',
                 dest = 'datadir', default = None,
                 help = "Path to the data directory")
    p.add_option('--config',
                 dest = 'config', default = None,
                 help = "Path to config.ini file")
    p.add_option('-p', '--pidfile',
                 dest = 'pidfile', default = None,
                 help = "Store the process id in the given file")

    options, args = p.parse_args()

    if options.debug:
        cherrystrap.LOGLEVEL = 2

    if options.quiet:
        cherrystrap.LOGLEVEL = 0

    if options.daemon:
        if not sys.platform == 'win32':
            cherrystrap.DAEMON = True
            cherrystrap.LOGLEVEL = 0
            cherrystrap.daemonize()
        else:
            print "Daemonize not supported under Windows, starting normally"

    if options.nolaunch:
        cherrystrap.LAUNCH_BROWSER = False

    if options.datadir:
        cherrystrap.DATADIR = str(options.datadir)
    else:
        cherrystrap.DATADIR = cherrystrap.PROG_DIR

    if options.config:
        cherrystrap.CONFIGFILE = str(options.config)
    else:
        cherrystrap.CONFIGFILE = os.path.join(cherrystrap.DATADIR, "config.ini")

    if options.pidfile:
        if cherrystrap.DAEMON:
            cherrystrap.PIDFILE = str(options.pidfile)

    # create and check (optional) paths
    if not os.path.exists(cherrystrap.DATADIR):
        try:
            os.makedirs(cherrystrap.DATADIR)
        except OSError:
            raise SystemExit('Could not create data directory: ' + cherrystrap.DATADIR + '. Exit ...')

    if not os.access(cherrystrap.DATADIR, os.W_OK):
        raise SystemExit('Cannot write to the data directory: ' + cherrystrap.DATADIR + '. Exit ...')

    # create database and config
    cherrystrap.DBFILE = os.path.join(cherrystrap.DATADIR, 'sqlite.db')
    cherrystrap.CFG = ConfigObj(cherrystrap.CONFIGFILE, encoding='utf-8')

    cherrystrap.initialize()

    if options.port:
        HTTP_PORT = int(options.port)
        logger.info('Starting cherrystrap on forced port: %s' % HTTP_PORT)
    else:
        HTTP_PORT = int(cherrystrap.HTTP_PORT)
        logger.info('Starting cherrystrap on port: %s' % cherrystrap.HTTP_PORT)

    if cherrystrap.DAEMON:
        cherrystrap.daemonize()

    # Try to start the server. 
    webStart.initialize({
                    'http_port': HTTP_PORT,
                    'http_host': cherrystrap.HTTP_HOST,
                    'http_root': cherrystrap.HTTP_ROOT,
                    'http_user': cherrystrap.HTTP_USER,
                    'http_pass': cherrystrap.HTTP_PASS,
            })

    if cherrystrap.LAUNCH_BROWSER and not options.nolaunch:
        cherrystrap.launch_browser(cherrystrap.HTTP_HOST, cherrystrap.HTTP_PORT, cherrystrap.HTTP_ROOT)

    cherrystrap.start()

    while True:
        if not cherrystrap.SIGNAL:

            try:
                time.sleep(1)
            except KeyboardInterrupt:
                cherrystrap.shutdown()
        else:
            if cherrystrap.SIGNAL == 'shutdown':
                cherrystrap.shutdown()
            elif cherrystrap.SIGNAL == 'restart':
                cherrystrap.shutdown(restart=True)
            else:
                cherrystrap.shutdown(restart=True, update=True)
            cherrystrap.SIGNAL = None
    return
Ejemplo n.º 25
0
def global_search(term=None, plot=None, media_type=None, playlist_name=None):
    term = str(term)
    termSafe = formatter.MySQL(term)
    artists = []
    albums = []
    songs = []
    movies = []
    mvideos = []
    series = []
    episodes = []

    try:
        SQLiteDB = database.SQLite_DBConnection()
        pass
    except:
        logger.info("There was a SQLite connection error.")

    try:
        table = table_map(cherrystrap.XBMC_VERSION)
        MySQLDB = database.MySQL_DBConnection()
        pass
    except:
        logger.info("There was a MySQL connection error.")

    if (not media_type) or (media_type=="artists"):
        artist_query = MySQLDB.select("SELECT idArtist, strArtist FROM %s WHERE strArtist LIKE '%s'" % (table['artist'], '%'+termSafe+'%'))
        if artist_query:
            for artist in artist_query:
                artistID = artist['idArtist']
                artistName = artist['strArtist']
                imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='artist'" % (table['music_art'], artistID))
                for image in imageUrls:
                    if image['type'] == 'thumb':
                        thumb_url = image['url']
                    elif image['type'] == 'fanart':
                        fanart_url = image['url']
                
                artistThumb, artistBanner, artistPoster, artistFan = formatter.get_image_locations(artistID, thumb_url=thumb_url, fanart_url=fanart_url)
                artists.append({
                    'artistID': artistID,
                    'artistName': artistName,
                    'artistThumb': artistThumb
                    })
    
    if (not media_type) or (media_type=="albums"):
        album_query = MySQLDB.select("SELECT idAlbum, strAlbum, strArtists FROM %s WHERE strAlbum LIKE '%s'" % (table['album'], '%'+termSafe+'%'))
        if album_query:
            for album in album_query:
                albumID = album['idAlbum']
                albumName = album['strAlbum']
                artistName = album['strArtists']
                imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='album'" % (table['music_art'], albumID))
                for image in imageUrls:
                    if image['type'] == 'thumb':
                        thumb_url = image['url']
                
                albumThumb, albumBanner, albumPoster, albumFan = formatter.get_image_locations(albumID, thumb_url=thumb_url)
                albums.append({
                    'albumID': albumID,
                    'albumName': albumName,
                    'albumThumb': albumThumb,
                    'artistName': artistName
                    })

    if (not media_type) or (media_type=="songs"):
        song_query = MySQLDB.select("SELECT idSong, strTitle, strArtists, idAlbum, strAlbum, strPath, strFileName FROM %s WHERE strTitle LIKE '%s'" % (table['songview'], '%'+termSafe+'%'))
        if song_query:
            for song in song_query:
                songID = song['idSong']
                songName = song['strTitle']
                artistName = song['strArtists']
                albumID = song['idAlbum']
                imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='album'" % (table['music_art'], albumID))
                for image in imageUrls:
                    if image['type'] == 'thumb':
                        thumb_url = image['url']
                
                songThumb, songBanner, songPoster, songFan = formatter.get_image_locations(songID, thumb_url=thumb_url)
                songs.append({
                    'songID': songID,
                    'songName': songName,
                    'songThumb': songThumb,
                    'artistName': artistName,
                    'albumID': albumID,
                    'path': song['strPath']+song['strFileName']
                    })

    if (not media_type) or (media_type=="movies"):
        movie_query = MySQLDB.select("SELECT idMovie, c00, strPath, strFileName FROM %s WHERE c00 LIKE '%s'" % (table['movieview'], '%'+termSafe+'%'))
        if movie_query:
            for movie in movie_query:
                movieID = movie['idMovie']
                movieName = movie['c00']
                imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='movie'" % (table['video_art'], movieID))
                for image in imageUrls:
                    if image['type'] == 'poster':
                        poster_url = image['url']
                    elif image['type'] == 'fanart':
                        fanart_url = image['url']
                
                movieThumb, movieBanner, moviePoster, movieFan = formatter.get_image_locations(movieID, poster_url=poster_url, fanart_url=fanart_url)
                movies.append({
                    'movieID': movieID,
                    'movieName': movieName,
                    'moviePoster': moviePoster,
                    'path': movie['strPath']+movie['strFileName']
                    })

    if (not media_type) or (media_type=="series"):
        series_query = MySQLDB.select("SELECT idShow, c00 FROM %s WHERE c00 LIKE '%s'" % (table['tvshow'], '%'+termSafe+'%'))
        if series_query:
            for show in series_query:
                showID = show['idShow']
                showName = show['c00']
                imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='tvshow'" % (table['video_art'], showID))
                for image in imageUrls:
                    if image['type'] == 'poster':
                        poster_url = image['url']
                    elif image['type'] == 'banner':
                        banner_url = image['url']
                    elif image['type'] == 'fanart':
                        fanart_url = image['url']
                
                seriesThumb, seriesBanner, seriesPoster, seriesFan = formatter.get_image_locations(movieID, poster_url=poster_url, banner_url=banner_url, fanart_url=fanart_url)
                series.append({
                    'showID': showID,
                    'showName': showName,
                    'showPoster': seriesPoster,
                    })

    if (not media_type) or (media_type=="episodes"):
        episode_query = MySQLDB.select("SELECT idEpisode, c00, idShow, strTitle, strPath, strFileName FROM %s WHERE c00 LIKE '%s'" % (table['episodeview'], '%'+termSafe+'%'))
        if episode_query:
            for episode in episode_query:
                episodeID = episode['idEpisode']
                episodeName = episode['c00']
                showName = episode['strTitle']
                showID = episode['idShow']
                imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='episode'" % (table['video_art'], episodeID))
                for image in imageUrls:
                    if image['type'] == 'thumb':
                        thumb_url = image['url']
                
                episodeThumb, episodeBanner, episodePoster, episodeFan = formatter.get_image_locations(episodeID, thumb_url=thumb_url)
                episodes.append({
                    'episodeID': episodeID,
                    'episodeName': episodeName,
                    'episodeThumb': episodeThumb,
                    'showName': showName,
                    'showID': showID,
                    'path': episode['strPath']+episode['strFileName']
                    })

    if (not media_type) or (media_type=="mvideos"):
        mvideo_query = MySQLDB.select("SELECT idMVideo, c00, c10, strPath, strFileName FROM %s WHERE c00 LIKE '%s'" % (table['musicvideoview'], '%'+termSafe+'%'))
        if mvideo_query:
            for mvideo in mvideo_query:
                mvideoID = mvideo['idMVideo']
                mvideoName = mvideo['c00']
                artistName = mvideo['c10']
                imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='musicvideo'" % (table['video_art'], mvideoID))
                for image in imageUrls:
                    if image['type'] == 'thumb':
                        thumb_url = image['url']
                
                mvideoThumb, mvideoBanner, mvideoPoster, mvideoFan = formatter.get_image_locations(mvideoID, thumb_url=thumb_url)
                mvideos.append({
                    'mvideoID': mvideoID,
                    'mvideoName': mvideoName,
                    'mvideoThumb': mvideoThumb,
                    'artistName': artistName,
                    'path': mvideo['strPath']+mvideo['strFileName']
                    })

        mvideo_query2 = MySQLDB.select("SELECT idMVideo, c00, c10, strPath, strFileName FROM %s WHERE c10 LIKE '%s'" % (table['musicvideoview'], '%'+termSafe+'%'))
        if mvideo_query2:
            for mvideo in mvideo_query2:
                mvideoID = mvideo['idMVideo']
                mvideoName = mvideo['c00']
                artistName = mvideo['c10']
                imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='musicvideo'" % (table['video_art'], mvideoID))
                for image in imageUrls:
                    if image['type'] == 'thumb':
                        thumb_url = image['url']
                
                mvideoThumb, mvideoBanner, mvideoPoster, mvideoFan = formatter.get_image_locations(mvideoID, thumb_url=thumb_url)
                mvideos.append({
                    'mvideoID': mvideoID,
                    'mvideoName': mvideoName,
                    'mvideoThumb': mvideoThumb,
                    'artistName': artistName,
                    'path': mvideo['strPath']+mvideo['strFileName']
                    })

    if plot:

        if (not media_type) or (media_type=="movies"):
            movie_query = MySQLDB.select("SELECT idMovie, c00, c01, strPath, strFileName FROM %s WHERE c01 LIKE '%s'" % (table['movieview'], '%'+termSafe+'%'))
            if movie_query:
                for movie in movie_query:
                    movieID = movie['idMovie']
                    movieName = movie['c00']
                    imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='movie'" % (table['video_art'], movieID))
                    for image in imageUrls:
                        if image['type'] == 'poster':
                            poster_url = image['url']
                        elif image['type'] == 'fanart':
                            fanart_url = image['url']
                    
                    movieThumb, movieBanner, moviePoster, movieFan = formatter.get_image_locations(movieID, poster_url=poster_url, fanart_url=fanart_url)
                    movies.append({
                        'movieID': movieID,
                        'movieName': movieName,
                        'moviePoster': moviePoster,
                        'path': movie['strPath']+movie['strFileName']
                        })

            movie_query = MySQLDB.select("SELECT idMovie, c00, c02, strPath, strFileName FROM %s WHERE c02 LIKE '%s'" % (table['movieview'], '%'+termSafe+'%'))
            if movie_query:
                for movie in movie_query:
                    movieID = movie['idMovie']
                    movieName = movie['c00']
                    imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='movie'" % (table['video_art'], movieID))
                    for image in imageUrls:
                        if image['type'] == 'poster':
                            poster_url = image['url']
                        elif image['type'] == 'fanart':
                            fanart_url = image['url']
                    
                    movieThumb, movieBanner, moviePoster, movieFan = formatter.get_image_locations(movieID, poster_url=poster_url, fanart_url=fanart_url)
                    movies.append({
                        'movieID': movieID,
                        'movieName': movieName,
                        'moviePoster': moviePoster,
                        'path': movie['strPath']+movie['strFileName']
                        })

            movie_query = MySQLDB.select("SELECT idMovie, c00, c03, strPath, strFileName FROM %s WHERE c03 LIKE '%s'" % (table['movieview'], '%'+termSafe+'%'))
            if movie_query:
                for movie in movie_query:
                    movieID = movie['idMovie']
                    movieName = movie['c00']
                    imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='movie'" % (table['video_art'], movieID))
                    for image in imageUrls:
                        if image['type'] == 'poster':
                            poster_url = image['url']
                        elif image['type'] == 'fanart':
                            fanart_url = image['url']
                    
                    movieThumb, movieBanner, moviePoster, movieFan = formatter.get_image_locations(movieID, poster_url=poster_url, fanart_url=fanart_url)
                    movies.append({
                        'movieID': movieID,
                        'movieName': movieName,
                        'moviePoster': moviePoster,
                        'path': movie['strPath']+movie['strFileName']
                        })

        if (not media_type) or (media_type=="episodes"):
            episode_query = MySQLDB.select("SELECT idEpisode, c00, idShow, strTitle, c01, strPath, strFileName FROM %s WHERE c01 LIKE '%s'" % (table['episodeview'], '%'+termSafe+'%'))
            if episode_query:
                for episode in episode_query:
                    episodeID = episode['idEpisode']
                    episodeName = episode['c00']
                    showName = episode['strTitle']
                    showID = episode['idShow']
                    imageUrls = MySQLDB.select("SELECT * FROM %s WHERE media_id = %s AND media_type='episode'" % (table['video_art'], episodeID))
                    for image in imageUrls:
                        if image['type'] == 'thumb':
                            thumb_url = image['url']
                    
                    episodeThumb, episodeBanner, episodePoster, episodeFan = formatter.get_image_locations(episodeID, thumb_url=thumb_url)
                    episodes.append({
                        'episodeID': episodeID,
                        'episodeName': episodeName,
                        'episodeThumb': episodeThumb,
                        'showName': showName,
                        'showID': showID,
                        'path': episode['strPath']+episode['strFileName']
                        })

        movies={v['movieID']:v for v in movies}.values()
        episodes={v['episodeID']:v for v in episodes}.values()
        mvideos={v['mvideoID']:v for v in mvideos}.values()

    if playlist_name:
        SQLiteDB.action("DELETE FROM generated_playlist")
        if media_type == "songs":
            for entry in songs:
                SQLiteDB.action("INSERT INTO generated_playlist (filepath) VALUES (?)", [entry['path']])
        elif media_type == "movies":
            for entry in movies:
                SQLiteDB.action("INSERT INTO generated_playlist (filepath) VALUES (?)", [entry['path']])
        elif media_type == "episodes":
            for entry in episodes:
                SQLiteDB.action("INSERT INTO generated_playlist (filepath) VALUES (?)", [entry['path']])
        elif media_type == "mvideos":
            for entry in mvideos:
                SQLiteDB.action("INSERT INTO generated_playlist (filepath) VALUES (?)", [entry['path']])

        save_playlist(playlist_name)

    return (term, artists, albums, songs, movies, mvideos, series, episodes, plot)
Ejemplo n.º 26
0
        #================================================================


        # Initialize the database
        try:
            createDb(DATABASE_TYPE, DATADIR, APP_NAME, MYSQL_HOST, MYSQL_PORT,
                MYSQL_USER, MYSQL_PASS)
        except Exception, e:
            logger.error("Error initializing the database: %s" % e)

        # Disable SSL verification for systems where SSL is broken
        if not VERIFY_SSL:
            try:
                import ssl
                ssl._create_default_https_context = ssl._create_unverified_context
                logger.info("SSL verification disabled per user preferences")
            except Exception, e:
                logger.warn("There was an error disabling SSL verification: %s" % s)
                pass

        # Get the currently installed version. Returns None, 'win32' or the git
        # hash.
        GIT_LOCAL, GIT_BRANCH = versioncheck.getVersion()

        # Write current version to a file, so we know which version did work.
        # This allows one to restore to that version. The idea is that if we
        # arrive here, most parts of the app seem to work.
        if GIT_LOCAL:
            version_lock_file = os.path.join(DATADIR, "version.lock")

            try:
Ejemplo n.º 27
0
        try:
            from jiraappy import injectApiConfigPut
            kwargs, errorList = injectApiConfigPut(kwargs, errorList)
        except Exception, e:
            logger.debug(
                "There was a problem injection application variables into API-PUT: %s"
                % e)
        #================================================================

        if len(kwargs) != 0:
            for key, value in kwargs.items():
                errorList.append("Key %s not expected" % key)

        cherrystrap.config_write()
        if not errorList:
            logger.info("All configuration settings successfully updated")
            return "{\"status\": \"success\", \
                \"message\": \"All configuration settings successfully updated\"}"

        else:
            logger.warn(
                "The following error(s) occurred while attempting to update settings: %s"
                % errorList)
            return "{\"status\": \"warning\", \
                \"message\": \"The following error(s) occurred while attempting to update settings: %s\"}" % errorList

    def DELETE(self, token=None):
        if token != cherrystrap.API_TOKEN:
            return "{\"status\": \"error\", \"message\": \"Invalid Token\"}"
        return "{\"status\": \"error\", \"message\": \"DELETE not available at this endpoint\"}"
Ejemplo n.º 28
0
def initialize():

    with INIT_LOCK:

        global __INITIALIZED__, FULL_PATH, PROG_DIR, LOGLEVEL, DAEMON, DATADIR, CONFIGFILE, CFG, LOGDIR, SERVER_NAME, HTTP_HOST, HTTP_PORT, HTTP_USER, HTTP_PASS, HTTP_ROOT, HTTP_LOOK, LAUNCH_BROWSER, \
        XBMC_VERSION, XBMC_HOST, XBMC_PORT, XBMC_USER, XBMC_PASSWORD, XBMC_THUMB_PATH

        if __INITIALIZED__:
            return False

        CheckSection('General')
        CheckSection('XBMC')

        try:
            HTTP_PORT = check_setting_int(CFG, 'General', 'http_port', 7949)
        except:
            HTTP_PORT = 7949

        if HTTP_PORT < 21 or HTTP_PORT > 65535:
            HTTP_PORT = 7949

        SERVER_NAME = check_setting_str(CFG, 'General', 'server_name', 'KodiDB')
        HTTP_HOST = check_setting_str(CFG, 'General', 'http_host', '0.0.0.0')
        HTTP_USER = check_setting_str(CFG, 'General', 'http_user', '')
        HTTP_PASS = check_setting_str(CFG, 'General', 'http_pass', '')
        HTTP_ROOT = check_setting_str(CFG, 'General', 'http_root', '')
        HTTP_LOOK = check_setting_str(CFG, 'General', 'http_look', 'default')
        LAUNCH_BROWSER = bool(check_setting_int(CFG, 'General', 'launch_browser', 0))
        LOGDIR = check_setting_str(CFG, 'General', 'logdir', '')

        XBMC_VERSION = check_setting_str(CFG, 'XBMC', 'xbmc_version', 'Helix')
        XBMC_HOST = check_setting_str(CFG, 'XBMC', 'xbmc_host', '')
        XBMC_PORT = check_setting_str(CFG, 'XBMC', 'xbmc_port', '')
        XBMC_USER = check_setting_str(CFG, 'XBMC', 'xbmc_user', '')
        XBMC_PASSWORD = check_setting_str(CFG, 'XBMC', 'xbmc_password', '')
        XBMC_THUMB_PATH = check_setting_str(CFG, 'XBMC', 'xbmc_thumb_path', '')

 
        if not LOGDIR:
            LOGDIR = os.path.join(DATADIR, 'Logs')

        THUMBDIR = os.path.join(DATADIR, 'data/images/Thumbnails')
        if not os.path.exists(THUMBDIR) and os.path.exists(XBMC_THUMB_PATH):
            try:
                os.symlink(XBMC_THUMB_PATH, THUMBDIR)
                logger.info("Thumbnail directory %s symlinked in data/images/Thumbnails" % XBMC_THUMB_PATH)
            except:
                logger.error("There was a problem creating the XBMC Thumbnails symlink")

        # Put the cache dir in the data dir for now
        CACHEDIR = os.path.join(DATADIR, 'cache')
        if not os.path.exists(CACHEDIR):
            try:
                os.makedirs(CACHEDIR)
            except OSError:
                logger.error('Could not create cachedir. Check permissions of: ' + DATADIR)

        # Create logdir
        if not os.path.exists(LOGDIR):
            try:
                os.makedirs(LOGDIR)
            except OSError:
                if LOGLEVEL:
                    print LOGDIR + ":"
                    print ' Unable to create folder for logs. Only logging to console.'

        # Start the logger, silence console logging if we need to
        logger.cherrystrap_log.initLogger(loglevel=LOGLEVEL)

        # Initialize the database
        try:
            dbcheck()
        except Exception, e:
            logger.error("Can't connect to the database: %s" % e)

        __INITIALIZED__ = True
        return True
Ejemplo n.º 29
0
def match_playlist(source, media_type):
    try:
        SQLiteDB = database.SQLite_DBConnection()
        pass
    except:
        logger.info("There was a SQLite connection error.")

    try:
        table = table_map(cherrystrap.XBMC_VERSION)
        MySQLDB = database.MySQL_DBConnection()
        pass
    except:
        logger.info("There was a MySQL connection error.")

    SQLiteDB.action("DELETE FROM generated_playlist")

    if source=="Billboard":
        need_artists = []
        have_albums = []
        need_albums = []
        
        yes_artists = []
        yes_albums = []
        no_artists = []
        no_albums = []

        SQLite_entries = SQLiteDB.select("SELECT * FROM billboard_music_releases WHERE billboard_nr_release = ?", [media_type])
        for entry in SQLite_entries:
            artist = entry['billboard_nr_artist']
            album = entry['billboard_nr_album']
            rank = entry['billboard_nr_rank']
            artist_clean = artist.lower()
            album_clean = album.lower()
            artistSafe = formatter.MySQL(artist_clean)
            albumSafe = formatter.MySQL(album_clean)
            artist_match = MySQLDB.action("SELECT strArtist FROM %s WHERE LOWER(strArtist) = '%s'" % (table['artist'], artistSafe)).fetchone()
            if not artist_match:
                no_artists.append({
                    'artist': artist,
                    'album': album
                })
            else:
                yes_artists.append({
                    'artist': artist,
                    'album': album,
                    'path': artist
                })
                if media_type=="Songs":
                    album_match = MySQLDB.select("SELECT strArtists, strTitle, strPath, strFileName FROM %s WHERE LOWER(strArtists) = '%s' AND LOWER(strTitle) = '%s'" % (table['songview'], artistSafe, albumSafe))
                    if album_match:
                        for match in album_match:
                            path = match['strPath']+match['strFileName']
                            yes_albums.append({
                                'artist': artist,
                                'album': album,
                                'path': path,
                                'rank': rank
                                })
                    else:
                        no_albums.append({
                            'artist': artist,
                            'album': album
                            })

                    have_albums={v['album']:v for v in yes_albums}.values()
                    have_albums=sorted(have_albums, key=lambda k: k['rank'])

                    need_albums={v['album']:v for v in no_albums}.values()
                    need_albums=sorted(need_albums, key=lambda k: k['artist'])

                elif media_type=="Albums":
                    album_match = MySQLDB.action("SELECT strArtists, strAlbum FROM %s WHERE LOWER(strArtists) = '%s' AND LOWER(strAlbum) = '%s'" % (table['album'], artistSafe, albumSafe)).fetchone()
                    if album_match:
                        song_match = MySQLDB.select("SELECT strArtists, strTitle, strPath, strFileName FROM %s WHERE LOWER(strArtists) = '%s' AND LOWER(strAlbum) = '%s'" % (table['songview'], artistSafe, albumSafe))
                        for match in song_match:
                            title = match['strTitle']
                            path = match['strPath']+match['strFileName']
                            yes_albums.append({
                                'artist': artist,
                                'album': title,
                                'path': path
                                })
                    else:
                        no_albums.append({
                            'artist': artist,
                            'album': album
                            })

                    have_albums={v['path']:v for v in yes_albums}.values()
                    have_albums=sorted(have_albums, key=lambda k: k['path'])

                    need_albums={v['album']:v for v in no_albums}.values()
                    need_albums=sorted(need_albums, key=lambda k: k['artist'])

                elif media_type=="Artists":
                    have_albums={v['artist']:v for v in yes_artists}.values()
                    have_albums=sorted(have_albums, key=lambda k: k['artist'])

            need_artists={v['artist']:v for v in no_artists}.values()
            need_artists=sorted(need_artists, key=lambda k: k['artist'])

    elif source=="Rotten Tomatoes":
        need_artists = []
        have_albums = []
        need_albums = [] 

        yes_albums = []
        no_albums = []

        SQLite_entries = SQLiteDB.select("SELECT * FROM rottentomatoes_movies")
        for entry in SQLite_entries:
            title = entry['rotten_title']
            percent = entry['rotten_percent']
            title_clean = title.lower()
            titleSafe = formatter.MySQL(title_clean)
            movie_match = MySQLDB.select("SELECT c00, strPath, strFileName FROM %s WHERE LOWER(c00) = '%s'" % (table['movieview'], titleSafe))
            if not movie_match:
                no_albums.append({
                    'artist': "",
                    'album': title,
                    'rank': percent
                })
            else:
                for movie in movie_match:
                    yes_albums.append({
                        'artist': "",
                        'album': title,
                        'rank': percent,
                        'path': movie['strPath']+movie['strFileName']
                    })

        have_albums={v['album']:v for v in yes_albums}.values()
        have_albums=sorted(have_albums, key=lambda k: k['rank'], reverse=True)

        need_albums={v['album']:v for v in no_albums}.values()
        need_albums=sorted(need_albums, key=lambda k: k['rank'], reverse=True)

    for entry in have_albums:
        SQLiteDB.action("INSERT INTO generated_playlist (filepath) VALUES (?)", [entry['path']])

    return (have_albums, need_artists, need_albums)
Ejemplo n.º 30
0
    # Get the latest version available from github
    logger.info('Retrieving latest version information from GitHub')
    url = 'https://api.github.com/repos/%s/%s/commits/%s' % (cherrystrap.GIT_USER, cherrystrap.GIT_REPO, cherrystrap.GIT_BRANCH)
    try:
        result = urllib2.urlopen(url).read()
        version = json.JSONDecoder().decode(result)
    except Exception, e:
        logger.warn('Could not get the latest version from GitHub. Are you running a local development version?: %s' % e)
        return cherrystrap.GIT_LOCAL

    cherrystrap.GIT_UPSTREAM = version['sha']
    logger.debug("Latest version is %s" % cherrystrap.GIT_UPSTREAM)

    # See how many commits behind we are
    if not cherrystrap.GIT_LOCAL:
        logger.info('You are running an unknown version of %s. Run the updater to identify your version' % cherrystrap.APP_NAME)
        return cherrystrap.GIT_UPSTREAM

    if cherrystrap.GIT_UPSTREAM == cherrystrap.GIT_LOCAL:
        logger.info('%s is up to date' % cherrystrap.APP_NAME)
        return cherrystrap.GIT_UPSTREAM

    logger.info('Comparing currently installed version with latest GitHub version')
    url = 'https://api.github.com/repos/%s/%s/compare/%s...%s' % (cherrystrap.GIT_USER, cherrystrap.GIT_REPO, cherrystrap.GIT_UPSTREAM, cherrystrap.GIT_LOCAL)
    try:
        result = urllib2.urlopen(url).read()
        commits = json.JSONDecoder().decode(result)
    except:
        logger.warn('Could not get commits behind from GitHub.')
        return cherrystrap.GIT_UPSTREAM
Ejemplo n.º 31
0
    def generateDiscussions(self):
        try:
            myDB = database.DBConnection()
            pass
        except:
            logger.info("There was a MySQL connection error.  Please check your Vanilla MySQL connection credentials")
            return serve_template(templatename="index.html")

        JSONDIR = os.path.join(cherrystrap.DATADIR,'cache','categories')
        if not os.path.exists(JSONDIR):
            try:
                os.makedirs(JSONDIR)
            except OSError:
                logger.error('Could not create user director. Check permissions of: ' + cherrystrap.DATADIR)
        
        discussionInfo=[]
        discussionCount = 0
        discussions = myDB.select("SELECT * FROM %s" % cherrystrap.VANILLA_DB+'.GDN_Discussion')
        for discussion in discussions:
            discussionCount += 1

            categoryID = discussion['CategoryID']
            discussionID = discussion['DiscussionID']
            posterID = discussion['InsertUserID']
            findUser = myDB.select("SELECT * FROM %s WHERE UserID = %s" % (cherrystrap.VANILLA_DB+'.GDN_User', posterID))
            for user in findUser:
                posterEmail = user['Email']

            commentsInfo = []
            #ORIGINAL POSTER
            commentsInfo.append({
                "author_email": posterEmail,
                "created_at": discussion['DateInserted'].strftime('%Y-%m-%dT%H:%M:%SZ'),
                "body": discussion['Body']
                })

            comments = myDB.select("SELECT * FROM %s WHERE DiscussionID = %s" % (cherrystrap.VANILLA_DB+'.GDN_Comment', discussionID))
            for comment in comments:
                commentUserID = comment['InsertUserID']
                commentCreated = comment['DateInserted'].strftime('%Y-%m-%dT%H:%M:%SZ')
                commentBody = comment['Body']
                findCommenter = myDB.select("SELECT * FROM %s WHERE UserID = %s" % (cherrystrap.VANILLA_DB+'.GDN_User', commentUserID))
                for commenter in findCommenter:
                    commentEmail = commenter['Email']

                commentsInfo.append({
                "author_email": commentEmail,
                "created_at": commentCreated,
                "body": commentBody
                })

            discussionInfo = {
                "title": discussion['Name'],
                "author_email": posterEmail,
                "created_at": discussion['DateInserted'].strftime('%Y-%m-%dT%H:%M:%SZ'),
                "comments": commentsInfo
                }

            OUTDIR = os.path.join(JSONDIR,str(categoryID),str(discussionID)+'.json')
            with open(OUTDIR, 'w') as outfile:
                json.dump(discussionInfo, outfile)
Ejemplo n.º 32
0
def main():

    # rename this thread
    threading.currentThread().name = "MAIN"

    # Set paths
    if hasattr(sys, 'frozen'):
        cherrystrap.FULL_PATH = os.path.abspath(sys.executable)
    else:
        cherrystrap.FULL_PATH = os.path.abspath(__file__)

    cherrystrap.PROG_DIR = os.path.dirname(cherrystrap.FULL_PATH)
    cherrystrap.ARGS = sys.argv[1:]

    cherrystrap.SYS_ENCODING = None

    try:
        locale.setlocale(locale.LC_ALL, "")
        cherrystrap.SYS_ENCODING = locale.getpreferredencoding()
    except (locale.Error, IOError):
        pass

    # for OSes that are poorly configured I'll just force UTF-8
    if not cherrystrap.SYS_ENCODING or cherrystrap.SYS_ENCODING in (
            'ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
        cherrystrap.SYS_ENCODING = 'UTF-8'

    # Set arguments
    from optparse import OptionParser

    p = OptionParser()
    p.add_option('-d',
                 '--daemon',
                 action="store_true",
                 dest='daemon',
                 help="Run the server as a daemon")
    p.add_option('-q',
                 '--quiet',
                 action="store_true",
                 dest='quiet',
                 help="Don't log to console")
    p.add_option('--debug',
                 action="store_true",
                 dest='debug',
                 help="Show debuglog messages")
    p.add_option('--nolaunch',
                 action="store_true",
                 dest='nolaunch',
                 help="Don't start browser")
    p.add_option('--port',
                 dest='port',
                 default=None,
                 help="Force webinterface to listen on this port")
    p.add_option('--datadir',
                 dest='datadir',
                 default=None,
                 help="Path to the data directory")
    p.add_option('--config',
                 dest='config',
                 default=None,
                 help="Path to config.ini file")
    p.add_option('-p',
                 '--pidfile',
                 dest='pidfile',
                 default=None,
                 help="Store the process id in the given file")

    options, args = p.parse_args()

    if options.debug:
        cherrystrap.LOGLEVEL = 2

    if options.quiet:
        cherrystrap.LOGLEVEL = 0

    if options.daemon:
        if not sys.platform == 'win32':
            cherrystrap.DAEMON = True
            cherrystrap.LOGLEVEL = 0
            cherrystrap.daemonize()
        else:
            print "Daemonize not supported under Windows, starting normally"

    if options.nolaunch:
        cherrystrap.LAUNCH_BROWSER = False

    if options.datadir:
        cherrystrap.DATADIR = str(options.datadir)
    else:
        cherrystrap.DATADIR = cherrystrap.PROG_DIR

    if options.config:
        cherrystrap.CONFIGFILE = str(options.config)
    else:
        cherrystrap.CONFIGFILE = os.path.join(cherrystrap.DATADIR,
                                              "config.ini")

    if options.pidfile:
        if cherrystrap.DAEMON:
            cherrystrap.PIDFILE = str(options.pidfile)

    # create and check (optional) paths
    if not os.path.exists(cherrystrap.DATADIR):
        try:
            os.makedirs(cherrystrap.DATADIR)
        except OSError:
            raise SystemExit('Could not create data directory: ' +
                             cherrystrap.DATADIR + '. Exit ...')

    if not os.access(cherrystrap.DATADIR, os.W_OK):
        raise SystemExit('Cannot write to the data directory: ' +
                         cherrystrap.DATADIR + '. Exit ...')

    # import config
    cherrystrap.CFG = ConfigObj(cherrystrap.CONFIGFILE, encoding='utf-8')

    cherrystrap.initialize()

    if options.port:
        HTTP_PORT = int(options.port)
        logger.info('Starting cherrystrap on forced port: %s' % HTTP_PORT)
    else:
        HTTP_PORT = int(cherrystrap.HTTP_PORT)

    if cherrystrap.DAEMON:
        cherrystrap.daemonize()

    # Check if pyOpenSSL is installed. It is required for certificate generation
    # and for CherryPy.
    if cherrystrap.HTTPS_ENABLED:
        try:
            import OpenSSL
        except ImportError:
            logger.warn("The pyOpenSSL module is missing. Install this " \
                "module to enable HTTPS. HTTPS will be disabled.")
            cherrystrap.HTTPS_ENABLED = False

    # Try to start the server.
    webStart.initialize({
        'http_port': HTTP_PORT,
        'http_host': cherrystrap.HTTP_HOST,
        'http_root': cherrystrap.HTTP_ROOT,
        'http_user': cherrystrap.HTTP_USER,
        'http_pass': cherrystrap.HTTP_PASS,
        'https_enabled': cherrystrap.HTTPS_ENABLED,
        'https_key': cherrystrap.HTTPS_KEY,
        'https_cert': cherrystrap.HTTPS_CERT,
        'verify_ssl': cherrystrap.VERIFY_SSL
    })

    if cherrystrap.LAUNCH_BROWSER and not options.nolaunch:
        cherrystrap.launch_browser(cherrystrap.HTTP_HOST,
                                   cherrystrap.HTTP_PORT,
                                   cherrystrap.HTTP_ROOT)

    cherrystrap.start()

    while True:
        if not cherrystrap.SIGNAL:

            try:
                time.sleep(1)
            except KeyboardInterrupt:
                cherrystrap.shutdown()
        else:
            if cherrystrap.SIGNAL == 'shutdown':
                cherrystrap.shutdown()
            elif cherrystrap.SIGNAL == 'restart':
                cherrystrap.shutdown(restart=True)
            else:
                cherrystrap.shutdown(restart=True, update=True)
            cherrystrap.SIGNAL = None
    return
Ejemplo n.º 33
0
        #===============================================================
        # Import a variable injector from your app's __init__.py
        try:
            from jiraappy import injectApiConfigPut
            kwargs, errorList = injectApiConfigPut(kwargs, errorList)
        except Exception, e:
            logger.debug("There was a problem injection application variables into API-PUT: %s" % e)
        #================================================================

        if len(kwargs) != 0:
            for key, value in kwargs.items():
                errorList.append("Key %s not expected" % key)

        cherrystrap.config_write()
        if not errorList:
            logger.info("All configuration settings successfully updated")
            return "{\"status\": \"success\", \
                \"message\": \"All configuration settings successfully updated\"}"
        else:
            logger.warn("The following error(s) occurred while attempting to update settings: %s" % errorList)
            return "{\"status\": \"warning\", \
                \"message\": \"The following error(s) occurred while attempting to update settings: %s\"}" % errorList

    def DELETE(self, token=None):
        if token != cherrystrap.API_TOKEN:
            return "{\"status\": \"error\", \"message\": \"Invalid Token\"}"
        return "{\"status\": \"error\", \"message\": \"DELETE not available at this endpoint\"}"

class log(object):
    exposed = True
Ejemplo n.º 34
0
    def _get_credentials(self, key):
        request_token = {}

        request_token['oauth_token'] = orielpy.TWITTER_TOKEN
        request_token['oauth_token_secret'] = orielpy.TWITTER_SECRET
        request_token['oauth_callback_confirmed'] = 'true'

        token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
        token.set_verifier(key)

        logger.info('Generating and signing request for an access token using key '+key)

        signature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1() #@UnusedVariable
        oauth_consumer             = oauth.Consumer(key=self.consumer_key, secret=self.consumer_secret)
        logger.info('oauth_consumer: '+str(oauth_consumer))
        oauth_client  = oauth.Client(oauth_consumer, token)
        logger.info('oauth_client: '+str(oauth_client))
        resp, content = oauth_client.request(self.ACCESS_TOKEN_URL, method='POST', body='oauth_verifier=%s' % key)
        logger.info('resp, content: '+str(resp)+','+str(content))

        access_token  = dict(parse_qsl(content))
        logger.info('access_token: '+str(access_token))

        logger.info('resp[status] = '+str(resp['status']))
        if resp['status'] != '200':
            logger.error('The request for a token with did not succeed: '+str(resp['status']))
            return False
        else:
            logger.info('Your Twitter Access Token key: %s' % access_token['oauth_token'])
            logger.info('Access Token secret: %s' % access_token['oauth_token_secret'])
            orielpy.TWITTER_TOKEN = access_token['oauth_token']
            orielpy.TWITTER_SECRET = access_token['oauth_token_secret']
            return True