Exemplo n.º 1
0
 def __init__(self, start_timestamp):
     self.size = 0
     self.tag_map = collections.defaultdict()
     self.dirpath = get_property("RFSCAN_PATH", "CONFIGS")
     self.filename = get_property("RFSCAN_FILE", "CONFIGS")
     self.file_time = start_timestamp
     self.start_time = self.timestamp_pretty()
Exemplo n.º 2
0
 def _eval_template(self, node_temp):
     kwargs = {}
     size_id = node_temp.getSizeId()
     size = node_temp.getSize()
     image_id = node_temp.getImageId()
     image = node_temp.getImage()
     #check if None attributes can be loaded from self.prop
     if size_id == None and self.prop != None:
         size_id = self.prop.getProperty('size_id')
     if image_id == None and self.prop != None:
         image_id = self.prop.getProperty('image_id')
     #if size or image are still None throw an Exception    
     if (size_id == None and 
         size == None) or (image_id == None and image == None):
         raise AttributeError('size or image not set!')
     #assign values
     name = node_temp.getNodeName()
     kwargs = get_property(self, name, 'name'
                           , kwargs, lambda x : x)
     if size_id:
         kwargs['size'] = NodeSize(id=size_id, name='', ram=-1, disk=-1, bandwidth=-1,
                                   price=1.0, driver=self.conn, extra={})
     else:
         kwargs['size'] = size.size
     if image_id:
         kwargs['image'] =  NodeImage(id=image_id, name='', driver=self.conn, extra={})
     else:
         kwargs['image'] = image.image
     
     location = node_temp.getLocationId()
     if location == None and self.prop != None:
         location= self.prop.getProperty('location_id')
     if location:
         kwargs['location'] = NodeLocation(id=location, name='', country='', driver=self.conn)
     elif node_temp.getLocation():
         kwargs['location'] = node_temp.getLocation().location
     else:
         pass
     #check keyName
     ex_keyname = node_temp.getKeyPair()
     kwargs = get_property(self, ex_keyname, 'ex_keyname'
                           , kwargs, lambda x : x)
     #inspect 'authentication'
     if node_temp.getAuthPassword():
         from libcloud.compute.base import NodeAuthPassword
         kwargs['auth'] = NodeAuthPassword(node_temp.getAuthPassword())
     elif node_temp.getAuthSshKey():
         from libcloud.compute.base import NodeAuthSSHKey
         kwargs['auth'] = NodeAuthSSHKey(node_temp.getAuthSshKey()) 
     return kwargs    
Exemplo n.º 3
0
 def _update_last_login(self):
     """
     Update the last_login time when a logged user browses something
     """
     last_login = get_property(self.env, 'last_login', None)
     if last_login != None:
         set_property(self.env, 'last_login', int(time()))
Exemplo n.º 4
0
def check_upgrade(env):
    """
    Check DB version, and if it's old, perform an upgrade
    """
    db_version = get_property(env, 'db_version')
    if not db_version: return False
        
    if int(DB_VERSION) > int(db_version):
        upgrade_db(env, int(db_version), int(DB_VERSION))
Exemplo n.º 5
0
    def _render_view(self,req):
        """
        Build template data for the Admin page
        """
        
        data = {}
        
        #Check if Project Management tables exist
        if get_property(self.env, 'db_version') == str(DB_VERSION):            
            data['database_ok'] = True
        else:
            return data

        status = get_property(self.env, 'status')

        statuses = [
            dict(name=x, label=y, selected=status == x) for x,y in sorted(STATUS.iteritems(), cmp=(lambda i1,i2: i1[1] > i2[1] and 1 or -1))
        ]

        project_data = {'tags': get_property(self.env, 'tags', '').split(),
                'company': get_property(self.env, 'company'),
                'date_started': get_property(self.env, 'date_started'),
                'date_scheduled': get_property(self.env, 'date_scheduled'),
                'date_finished': get_property(self.env, 'date_finished'),
                'percent': get_property(self.env, 'percent'),
                'status': STATUS[status],
                'client': get_property(self.env, 'client'),
                'manager': get_property(self.env, 'manager'),
                'statuses': statuses}
        
        data['admin'] = {}
        data['admin']['project'] = project_data
        data['admin']['date_hint'] = DATE_HINT
        data['admin']['all_tags'] = sorted(get_all_tags(self.env))
        
        return data
Exemplo n.º 6
0
 def _eval_deploy_template(self, node_temp, kwargs):
     #deploy_node params
     ssh_username = node_temp.getSshUsername()
     kwargs = get_property(self, ssh_username, 'ssh_username'
                           , kwargs, lambda x : x)
     ssh_alternate_usernames = node_temp.getSshAlternateUsernames()
     kwargs = get_property_list(self, ssh_alternate_usernames, 'ssh_alternate_usernames'
                           , kwargs, lambda x : x)
     ssh_port = node_temp.getSshPort()
     kwargs = get_property(self, ssh_port, 'ssh_port'
                           , kwargs, lambda x : int(x))
     ssh_timeout = node_temp.getSshTimeout()
     kwargs = get_property(self, ssh_timeout, 'ssh_timeout'
                           , kwargs, lambda x : float(x))
     ssh_key = node_temp.getSshKey()
     kwargs = get_property(self, ssh_key, 'ssh_key'
                           , kwargs, lambda x : x)
     timeout = node_temp.getTimeout()
     kwargs = get_property(self, timeout, 'timeout'
                           , kwargs, lambda x : int(x))
     max_tries = node_temp.getMaxTries()
     kwargs = get_property(self, max_tries, 'max_tries'
                           , kwargs, lambda x : int(x))
     ssh_interface = node_temp.getSshInterface()
     kwargs = get_property(self, ssh_interface, 'ssh_interface'
                           , kwargs, lambda x : x)
     #get the deployment classes
     deployments = node_temp.getDeploy()
     if deployments:
         msd = MultiStepDeployment()
         for deploy in deployments:
             if isinstance(deploy, SshKeyDeployment):
                 msd.add(SSHKeyDeployment(str(deploy.getKey())))
             elif isinstance(deploy, FileDeployment):
                 msd.add(FileDeployment(deploy.getSource(), deploy.getTarget()))
             elif isinstance(deploy, ScriptDeployment):
                 args = deploy.getArgs()
                 arg_lst = self._parse_arg_list(args)
                 msd.add(ScriptDeployment(deploy.getScriptContent(), arg_lst, 
                                          deploy.getName(), deploy.getDelete()))
             elif isinstance(deploy, ScriptFileDeployment):
                 args = deploy.getArgs()
                 arg_lst = self._parse_arg_list(args)
                 msd.add(ScriptFileDeployment(deploy.getScriptPath(), arg_lst,
                                               deploy.getName(), deploy.getDelete()))
         kwargs['deploy'] = msd
     return kwargs
Exemplo n.º 7
0
    def run(self):
        """Main service loop"""
        self.log('Service started', 0)

        while not self.abortRequested():
            # check every 1 sec
            if self.waitForAbort(1):
                # Abort was requested while waiting. We should exit
                break

            if not self.player.is_tracking():
                continue

            if bool(get_property('PseudoTVRunning') == 'True'):
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            if get_setting_bool('disableNextUp'):
                # Next Up is disabled
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            # Method isExternalPlayer() was added in Kodi v18 onward
            if kodi_version_major() >= 18 and self.player.isExternalPlayer():
                self.log('Up Next tracking stopped, external player detected',
                         2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            last_file = self.player.get_last_file()
            try:
                current_file = self.player.getPlayingFile()
            except RuntimeError:
                self.log(
                    'Up Next tracking stopped, failed player.getPlayingFile()',
                    2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            if last_file and last_file == from_unicode(current_file):
                # Already processed this playback before
                continue

            try:
                total_time = self.player.getTotalTime()
            except RuntimeError:
                self.log(
                    'Up Next tracking stopped, failed player.getTotalTime()',
                    2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            if total_time == 0:
                self.log('Up Next tracking stopped, no file is playing', 2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            try:
                play_time = self.player.getTime()
            except RuntimeError:
                self.log('Up Next tracking stopped, failed player.getTime()',
                         2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            notification_time = self.api.notification_time(
                total_time=total_time)
            if total_time - play_time > notification_time:
                # Media hasn't reach notification time yet, waiting a bit longer...
                continue

            self.player.set_last_file(from_unicode(current_file))
            self.log(
                'Show notification as episode (of length %d secs) ends in %d secs'
                % (total_time, notification_time), 2)
            self.playback_manager.launch_up_next()
            self.log('Up Next style autoplay succeeded', 2)
            self.player.disable_tracking()

        self.log('Service stopped', 0)
Exemplo n.º 8
0
    def run(self):
        ''' Main service loop '''
        self.log('Service started', 0)

        while not self.abortRequested():
            # check every 1 sec
            if self.waitForAbort(1):
                # Abort was requested while waiting. We should exit
                break

            if not self.player.is_tracking():
                continue

            up_next_disabled = bool(get_setting('disableNextUp') == 'true')
            if bool(get_property('PseudoTVRunning') ==
                    'True') or up_next_disabled:
                continue

            last_file = self.player.get_last_file()
            try:
                current_file = self.player.getPlayingFile()
            except RuntimeError:
                self.log(
                    'Failed getPlayingFile: No file is playing - stop up next tracking',
                    2)
                self.player.disable_tracking()
                continue

            if last_file and last_file == current_file:
                continue

            try:
                total_time = self.player.getTotalTime()
            except RuntimeError:
                self.log(
                    'Failed getTotalTime: No file is playing - stop up next tracking',
                    2)
                self.player.disable_tracking()
                continue

            if total_time == 0:
                continue

            try:
                play_time = self.player.getTime()
            except RuntimeError:
                self.log(
                    'Failed getTime: No file is playing - stop up next tracking',
                    2)
                self.player.disable_tracking()
                continue

            notification_time = self.api.notification_time(
                total_time=total_time)
            if total_time - play_time > notification_time:
                continue

            self.player.set_last_file(from_unicode(current_file))
            self.log(
                'Show notification as episode (of length %d secs) ends in %d secs'
                % (total_time, notification_time), 2)
            self.playback_manager.launch_up_next()
            self.log('Up Next style autoplay succeeded', 2)
            self.player.disable_tracking()

        self.log('Service stopped', 0)
Exemplo n.º 9
0
    def _check_video(self, data=None, encoding=None):
        # Only process one start at a time unless addon data has been received
        if self.state.starting and not data:
            return
        self.log('Starting video check')
        # Increment starting counter
        self.state.starting += 1
        start_num = max(1, self.state.starting)

        # onPlayBackEnded for current file can trigger after next file starts
        # Wait additional 5s after onPlayBackEnded or last start
        wait_count = 5 * start_num
        while not self.abortRequested() and wait_count:
            self.waitForAbort(1)
            wait_count -= 1

        # Get video details, exit if no video playing
        with self.player as check_fail:
            playing_file = self.player.getPlayingFile()
            total_time = self.player.getTotalTime()
            media_type = self.player.get_media_type()
            check_fail = False
        if check_fail:
            self.log('Skip video check: nothing playing', utils.LOGWARNING)
            return
        self.log('Playing: {0} - {1}'.format(media_type, playing_file))

        # Exit if starting counter has been reset or new start detected or
        # starting state has been reset by playback error/end/stop
        if not self.state.starting or start_num != self.state.starting:
            self.log('Skip video check: playing item not fully loaded')
            return
        self.state.starting = 0
        self.state.playing = 1

        if utils.get_property('PseudoTVRunning') == 'True':
            self.log('Skip video check: PsuedoTV detected')
            return

        if self.player.isExternalPlayer():
            self.log('Skip video check: external player detected')
            return

        # Exit if UpNext playlist handling has not been enabled
        playlist_position = api.get_playlist_position()
        if playlist_position and not self.state.enable_playlist:
            self.log('Skip video check: playlist handling not enabled')
            return

        # Use new addon data if provided or erase old addon data.
        # Note this may cause played in a row count to reset incorrectly if
        # playlist of mixed non-addon and addon content is used
        self.state.set_addon_data(data, encoding)
        addon_type = self.state.get_addon_type(playlist_position)

        # Start tracking if UpNext can handle the currently playing video
        # Process now playing video to get episode details and save playcount
        now_playing_item = self.state.process_now_playing(
            playlist_position, addon_type, media_type
        )
        if now_playing_item:
            self.state.set_tracking(playing_file)
            self.state.reset_queue()

            # Store popup time and check if cue point was provided
            self.state.set_popup_time(total_time)

            # Handle demo mode functionality and notification
            demo.handle_demo_mode(
                monitor=self,
                player=self.player,
                state=self.state,
                now_playing_item=now_playing_item
            )
            # Start tracking playback in order to launch popup at required time
            self.tracker.start()
            return

        self.log('Skip video check: UpNext unable to handle playing item')
        if self.state.is_tracking():
            self.state.reset()