def process_change(self, change, items_info, export):
     change_type = None
     changed_item_id = change['id']
     Logger.debug('Change: %s' % Utils.str(change))
     if changed_item_id != export['id']:
         changed_item_name = change['name']
         deleted = Utils.get_safe_value(change, 'deleted')
         parent_id = change['parent']
         is_folder = 'folder' in change
         if not is_folder:
             changed_item_name += ExportManager._strm_extension
         if changed_item_id in items_info:
             item_info = items_info[changed_item_id]
             Logger.debug('item_info: %s' % Utils.str(item_info))
             item_info_path = item_info['full_local_path']
             if KodiUtils.file_exists(item_info_path):
                 if deleted:
                     change_type = self.process_change_delete(items_info, changed_item_id, is_folder)
                 elif parent_id != item_info['parent'] or changed_item_name != item_info['name']:
                     if parent_id in items_info:
                         change_type = 'move'
                         Logger.debug('Change is move')
                         parent_item_info = items_info[parent_id]
                         parent_item_path = parent_item_info['full_local_path']
                         new_path = os.path.join(parent_item_path, changed_item_name)
                         if is_folder:
                             new_path = os.path.join(new_path, '')
                         if KodiUtils.file_rename(item_info_path, new_path):
                             ExportManager.remove_item_info(items_info, changed_item_id)
                             ExportManager.add_item_info(items_info, changed_item_id, changed_item_name, new_path, parent_id)
                         else:
                             change_type = 'retry'
                     else:
                         Logger.debug('Change is move but parent not in item list. Change is delete')
                         change_type = self.process_change_delete(items_info, changed_item_id, is_folder)
             else:
                 Logger.debug('Invalid state. Changed item not found: %s. Deleting from item list.' % item_info_path)
                 change_type = self.process_change_delete(items_info, changed_item_id, is_folder)
         elif parent_id in items_info and not deleted:
             content_type = export['content_type']
             item_name_extension = change['name_extension']
             if is_folder or (('video' in change or item_name_extension in self._video_file_extensions) and content_type == 'video') or ('audio' in change and content_type == 'audio'):
                 change_type = 'add'
                 Logger.debug('Change is new item')
                 parent_item_info = items_info[parent_id]
                 parent_item_path = parent_item_info['full_local_path']
                 new_path = os.path.join(parent_item_path, changed_item_name)
                 if is_folder:
                     new_path = os.path.join(new_path, '')
                     if not KodiUtils.mkdirs(new_path):
                         change_type = 'retry'
                 else:
                     ExportManager.create_strm(export['driveid'], change, new_path, content_type, 'plugin://%s/' % self.addonid)
                 if change_type != 'retry':
                     ExportManager.add_item_info(items_info, changed_item_id, changed_item_name, new_path, parent_id)
     Logger.debug('change type: %s ' % Utils.str(change_type))
     return change_type
Ejemplo n.º 2
0
 def process_change_delete(self, items_info, item_id, is_folder):
     change_type = 'delete'
     item_info = items_info[item_id]
     item_info_path = item_info['full_local_path']
     if KodiUtils.file_exists(item_info_path):
         if is_folder:
             Logger.debug('Change is delete folder: %s' % item_info_path)
             if not self.remove_folder(item_info_path):
                 change_type = 'retry'
         else:
             Logger.debug('Change is delete file')
             if not KodiUtils.file_delete(item_info_path):
                 change_type = 'retry'
     if change_type != 'retry':
         ExportManager.remove_item_info(items_info, item_id)
     return change_type
Ejemplo n.º 3
0
 def process_change_delete(self, change, items_info):
     change_type = 'delete'
     changed_item_id = change['id']
     item_info = items_info[changed_item_id]
     item_info_path = item_info['full_local_path']
     item_type = item_info['type']
     is_folder = item_type == 'folder'
     Logger.debug('deleting: %s' % item_info_path)
     if KodiUtils.file_exists(item_info_path):
         if is_folder:
             change_type += '_folder'
             if not Utils.remove_folder(item_info_path,
                                        self._system_monitor):
                 change_type += '_retry'
         else:
             change_type += '_file'
             if not KodiUtils.file_delete(item_info_path):
                 change_type += '_retry'
     else:
         Logger.debug('file already deleted: %s' % item_info_path)
         change_type += '_ignored'
     ExportManager.remove_item_info(items_info, changed_item_id)
     return change_type
Ejemplo n.º 4
0
 def process_change(self, change, items_info, export):
     change_type = None
     changed_item_id = change['id']
     Logger.debug('Change: %s' % Utils.str(change))
     if changed_item_id != export['id']:
         changed_item_name = Utils.get_safe_value(change, 'name', '')
         deleted = Utils.get_safe_value(change, 'removed')
         parent_id = Utils.get_safe_value(change, 'parent', '')
         if changed_item_id in items_info:
             item_info = items_info[changed_item_id]
             item_type = item_info['type']
             is_folder = item_type == 'folder'
             Logger.debug('item_info: %s' % Utils.str(item_info))
             item_info_path = item_info['full_local_path']
             if KodiUtils.file_exists(item_info_path):
                 if deleted:
                     change_type = self.process_change_delete(
                         items_info, changed_item_id, is_folder)
                 elif parent_id != item_info[
                         'parent'] or changed_item_name != item_info['name']:
                     if parent_id in items_info:
                         change_type = 'move'
                         Logger.debug('Change is move')
                         parent_item_info = items_info[parent_id]
                         parent_item_path = parent_item_info[
                             'full_local_path']
                         new_path = os.path.join(
                             parent_item_path,
                             Utils.unicode(changed_item_name))
                         if is_folder:
                             new_path = os.path.join(new_path, '')
                         if KodiUtils.file_rename(item_info_path, new_path):
                             ExportManager.remove_item_info(
                                 items_info, changed_item_id)
                             ExportManager.add_item_info(
                                 items_info, changed_item_id,
                                 Utils.unicode(changed_item_name), new_path,
                                 parent_id, item_type)
                         else:
                             change_type = 'retry'
                     else:
                         Logger.debug(
                             'Change is move but parent not in item list. Change is delete'
                         )
                         change_type = self.process_change_delete(
                             items_info, changed_item_id, is_folder)
             else:
                 Logger.debug(
                     'Invalid state. Changed item not found: %s. Deleting from item list.'
                     % item_info_path)
                 change_type = self.process_change_delete(
                     items_info, changed_item_id, is_folder)
         elif parent_id in items_info and not deleted:
             is_folder = 'application/vnd.google-apps.folder' in change.get(
                 'mimetype')
             content_type = export['content_type']
             item_name_extension = change['name_extension']
             is_stream_file = (
                 ('video' in change
                  or item_name_extension in self._video_file_extensions)
                 and content_type == 'video') or ('audio' in change and
                                                  content_type == 'audio')
             item_type = 'folder' if is_folder else 'file'
             if is_folder or is_stream_file or (
                     export['nfo_export'] and
                 ('nfo' in item_name_extension
                  or 'text/x-nfo' in change.get("mimetype"))):
                 change_type = 'add'
                 Logger.debug('Change is new item')
                 parent_item_info = items_info[parent_id]
                 parent_item_path = parent_item_info['full_local_path']
                 new_path = os.path.join(parent_item_path,
                                         Utils.unicode(changed_item_name))
                 if is_folder:
                     new_path = os.path.join(new_path, '')
                     if not KodiUtils.mkdirs(new_path):
                         change_type = 'retry'
                 elif is_stream_file:
                     new_path += '.strm'
                     ExportManager.create_strm(
                         export['driveid'], change, new_path, content_type,
                         'plugin://%s/' % self.addonid)
                 else:
                     ExportManager.create_nfo(
                         export['driveid'], change,
                         Utils.unicode(changed_item_name), new_path)
                 if change_type != 'retry':
                     ExportManager.add_item_info(
                         items_info, changed_item_id,
                         Utils.unicode(changed_item_name), new_path,
                         parent_id, item_type)
     Logger.debug('change type: %s ' % Utils.str(change_type))
     return change_type