Beispiel #1
0
    def _cache_image_from_file(self, image_path, img_type, indexer_id):
        """
        Takes the image provided and copies it to the cache folder

        :param image_path: path to the image we're caching
        :param img_type: BANNER or POSTER or FANART
        :param indexer_id: id of the show this image belongs to
        :return: bool representing success
        """

        # generate the path based on the type & indexer_id
        if img_type == self.POSTER:
            dest_path = self.poster_path(indexer_id)
        elif img_type == self.BANNER:
            dest_path = self.banner_path(indexer_id)
        elif img_type == self.FANART:
            dest_path = self.fanart_path(indexer_id)
        else:
            logger.log(u"Invalid cache image type: " + str(img_type), logger.ERROR)
            return False

        # make sure the cache folder exists before we try copying to it
        if not ek(os.path.isdir, self._cache_dir()):
            logger.log(u"Image cache dir didn't exist, creating it at " + str(self._cache_dir()))
            ek(os.makedirs, self._cache_dir())

        if not ek(os.path.isdir, self._thumbnails_dir()):
            logger.log(u"Thumbnails cache dir didn't exist, creating it at " + str(self._thumbnails_dir()))
            ek(os.makedirs, self._thumbnails_dir())

        logger.log(u"Copying from " + image_path + " to " + dest_path)
        helpers.copyFile(image_path, dest_path)

        return True
Beispiel #2
0
    def _copy(self, file_path, new_path, associated_files=False):

        if associated_files:
            file_list = self._list_associated_files(file_path)
        else:
            file_list = [file_path]

        if not file_list:
            self._log(u"There were no files associated with " + file_path + ", not copying anything", logger.DEBUG)
            return

        for cur_file_path in file_list:

            cur_file_name = ek.ek(os.path.basename, cur_file_path)
            new_file_path = ek.ek(os.path.join, new_path, cur_file_name)

            self._log(u"Copying file from " + cur_file_path + " to " + new_file_path, logger.DEBUG)
            try:
                helpers.copyFile(cur_file_path, new_file_path)
            except (IOError, OSError), e:
                logger.log(
                    "Unable to copy file " + cur_file_path + " to " + new_file_path + ": " + str(e).decode("utf-8"),
                    logger.ERROR,
                )
                raise e
Beispiel #3
0
    def _copy(self, file_path, new_path, associated_files=False):

        if associated_files:
            file_list = self._list_associated_files(file_path)
        else:
            file_list = [file_path]

        if not file_list:
            self._log(
                u"There were no files associated with " + file_path +
                ", not copying anything", logger.DEBUG)
            return

        for cur_file_path in file_list:

            cur_file_name = ek.ek(os.path.basename, cur_file_path)
            new_file_path = ek.ek(os.path.join, new_path, cur_file_name)

            self._log(
                u"Copying file from " + cur_file_path + " to " + new_file_path,
                logger.DEBUG)
            try:
                helpers.copyFile(cur_file_path, new_file_path)
            except (IOError, OSError), e:
                logger.log(
                    "Unable to copy file " + cur_file_path + " to " +
                    new_file_path + ": " + str(e).decode('utf-8'),
                    logger.ERROR)
                raise e
Beispiel #4
0
        def _int_copy(cur_file_path, new_file_path):

            self._log(u"Copying file from " + cur_file_path + " to " + new_file_path, logger.DEBUG)
            try:
                helpers.copyFile(cur_file_path, new_file_path)
                helpers.chmodAsParent(new_file_path)
            except (IOError, OSError), e:
                logger.log(u"Unable to copy file " + cur_file_path + " to " + new_file_path + ": " + ex(e), logger.ERROR)
                raise e
Beispiel #5
0
        def _int_copy(cur_file_path, new_file_path, success_tmpl=u' %s to %s'):

            try:
                helpers.copyFile(cur_file_path, new_file_path)
                helpers.chmodAsParent(new_file_path)
                self._log(u'Copied file from' + (success_tmpl % (cur_file_path, new_file_path)), logger.DEBUG)
            except (IOError, OSError), e:
                self._log(u'Unable to copy %s<br />.. %s' % (success_tmpl % (cur_file_path, new_file_path), str(e)), logger.ERROR)
                raise e
Beispiel #6
0
        def _int_copy (cur_file_path, new_file_path):

            self._log(u"Copying file from "+cur_file_path+" to "+new_file_path, logger.DEBUG)
            try:
                helpers.copyFile(cur_file_path, new_file_path)
                helpers.chmodAsParent(new_file_path)
                if sickbeard.UPDATE_DIRECTORY_TIMESTAMP: helpers.touchPath(helpers.getParentDirectory(new_file_path))
            except (IOError, OSError), e:
                logger.log("Unable to copy file "+cur_file_path+" to "+new_file_path+": "+ex(e), logger.ERROR)
                raise e
Beispiel #7
0
    def _cache_image_from_file(self,
                               image_path,
                               img_type,
                               indexer_id,
                               move_file=False):
        """
        Takes the image provided and copies or moves it to the cache folder

        returns: full path to cached file or None

        image_path: path to the image to cache
        img_type: BANNER, POSTER, or FANART
        indexer_id: id of the show this image belongs to
        move_file: True if action is to move the file else file should be copied
        """

        # generate the path based on the type & indexer_id
        fanart_subdir = []
        if img_type == self.POSTER:
            dest_path = self.poster_path(indexer_id)
        elif img_type == self.BANNER:
            dest_path = self.banner_path(indexer_id)
        elif img_type == self.FANART:
            with open(image_path, mode='rb') as resource:
                crc = '%05X' % (zlib.crc32(resource.read()) & 0xFFFFFFFF)
            fanart_subdir = [self._fanart_dir(indexer_id)]
            dest_path = self.fanart_path(indexer_id).replace(
                '.fanart.jpg', '.%s.fanart.jpg' % crc)
        else:
            logger.log(u'Invalid cache image type: ' + str(img_type),
                       logger.ERROR)
            return False

        for cache_dir in [
                self._cache_dir(),
                self._thumbnails_dir(),
                self._fanart_dir()
        ] + fanart_subdir:
            helpers.make_dirs(cache_dir)

        logger.log(u'%sing from %s to %s' %
                   (('Copy', 'Mov')[move_file], image_path, dest_path))
        if move_file:
            helpers.moveFile(image_path, dest_path)
        else:
            helpers.copyFile(image_path, dest_path)

        return ek.ek(os.path.isfile, dest_path) and dest_path or None
Beispiel #8
0
    def _cache_image_from_file(self, image_path, img_type, tvdb_id):
        if img_type == self.POSTER:
            dest_path = self.poster_path(tvdb_id)
        elif img_type == self.BANNER:
            dest_path = self.banner_path(tvdb_id)
        else:
            logger.log(u"Invalid cache image type: "+str(img_type), logger.ERROR)
            return False

        if not ek.ek(os.path.isdir, self._cache_dir()):
            logger.log(u"Image cache dir didn't exist, creating it at "+str(self._cache_dir()))
            ek.ek(os.makedirs, self._cache_dir())

        logger.log(u"Copying from "+image_path+" to "+dest_path)
        helpers.copyFile(image_path, dest_path)
        
        return True
Beispiel #9
0
    def _cache_image_from_file(self, image_path, img_type, tvdb_id):
        if img_type == self.POSTER:
            dest_path = self.poster_path(tvdb_id)
        elif img_type == self.BANNER:
            dest_path = self.banner_path(tvdb_id)
        else:
            logger.log(u"Invalid cache image type: " + str(img_type),
                       logger.ERROR)
            return False

        if not ek.ek(os.path.isdir, self._cache_dir()):
            logger.log(u"Image cache dir didn't exist, creating it at " +
                       str(self._cache_dir()))
            ek.ek(os.makedirs, self._cache_dir())

        logger.log(u"Copying from " + image_path + " to " + dest_path)
        helpers.copyFile(image_path, dest_path)

        return True
Beispiel #10
0
    def _cache_image_from_file(self, image_path, img_type, indexer_id, move_file=False):
        """
        Takes the image provided and copies or moves it to the cache folder

        returns: full path to cached file or None

        image_path: path to the image to cache
        img_type: BANNER, POSTER, or FANART
        indexer_id: id of the show this image belongs to
        move_file: True if action is to move the file else file should be copied
        """

        # generate the path based on the type & indexer_id
        fanart_subdir = []
        if img_type == self.POSTER:
            dest_path = self.poster_path(indexer_id)
        elif img_type == self.BANNER:
            dest_path = self.banner_path(indexer_id)
        elif img_type == self.FANART:
            with open(image_path, mode='rb') as resource:
                crc = '%05X' % (zlib.crc32(resource.read()) & 0xFFFFFFFF)
            fanart_subdir = [self._fanart_dir(indexer_id)]
            dest_path = self.fanart_path(indexer_id).replace('.fanart.jpg', '.%s.fanart.jpg' % crc)
        else:
            logger.log(u'Invalid cache image type: ' + str(img_type), logger.ERROR)
            return False

        for cache_dir in [self._cache_dir(), self._thumbnails_dir(), self._fanart_dir()] + fanart_subdir:
            helpers.make_dirs(cache_dir)

        logger.log(u'%sing from %s to %s' % (('Copy', 'Mov')[move_file], image_path, dest_path))
        if move_file:
            helpers.moveFile(image_path, dest_path)
        else:
            helpers.copyFile(image_path, dest_path)

        return ek.ek(os.path.isfile, dest_path) and dest_path or None
Beispiel #11
0
    def _copy(self, file_path, new_path, new_base_name, associated_files=False):

        if associated_files:
            file_list = self._list_associated_files(file_path)
        else:
            file_list = [file_path]

        if not file_list:
            self._log(u"There were no files associated with "+file_path+", not copying anything", logger.DEBUG)
            return
        
        for cur_file_path in file_list:

            cur_file_name = ek.ek(os.path.basename, cur_file_path)
            
            #AW: If new base name then convert name
            if new_base_name:
                # get the extension
                cur_extension = cur_file_path.rpartition('.')[-1]
            
                # replace .nfo with .nfo-orig to avoid conflicts
                if cur_extension == 'nfo':
                    cur_extension = 'nfo-orig'
                    
                new_file_name = new_base_name +'.' + cur_extension
            else:
                new_file_name = cur_file_name
                
            new_file_path = ek.ek(os.path.join, new_path, new_file_name)

            self._log(u"Copying file from "+cur_file_path+" to "+new_file_path, logger.DEBUG)
            try:
                helpers.copyFile(cur_file_path, new_file_path)
            except (IOError, OSError), e:
                logger.log("Unable to copy file "+cur_file_path+" to "+new_file_path+": "+str(e).decode('utf-8'), logger.ERROR)
                raise e
Beispiel #12
0
def _update_zoneinfo():
    global sb_timezone
    sb_timezone = tz.tzlocal()

    # TODO `git subtree pull` commands on updates

    loc_zv = helpers.real_path(
        ek.ek(join, ek.ek(os.path.dirname, __file__),
              u'../lib/network_timezones/zoneinfo.txt'))

    # Read version file
    try:
        with open(loc_zv, 'r') as file:
            data = file.read()
        if not data:
            raise

        # Filename of existing zoneinfo
        if lib.dateutil.zoneinfo.ZONEINFOFILE is not None:
            cur_zoneinfo = ek.ek(basename, lib.dateutil.zoneinfo.ZONEINFOFILE)
        else:
            cur_zoneinfo = None

        # Filename and hash of new zoneinfo
        (new_zoneinfo,
         zoneinfo_md5) = data.decode('utf-8').strip().rsplit(u' ')
    except Exception as e:
        logger.log(u'Crazy problem with zoneinfo: %s' % ex(e), logger.ERROR)
        return

    if (cur_zoneinfo is not None) and (new_zoneinfo == cur_zoneinfo):
        return

    # now load the new zoneinfo
    loc_tar = helpers.real_path(
        ek.ek(join, ek.ek(os.path.dirname, __file__),
              u'../lib/network_timezones/%s' % new_zoneinfo))

    zonefile = helpers.real_path(
        ek.ek(join, ek.ek(os.path.dirname, lib.dateutil.zoneinfo.__file__),
              new_zoneinfo))
    zonefile_tmp = re.sub(r'\.tar\.gz$', '.tmp', zonefile)

    if ek.ek(os.path.exists, zonefile_tmp):
        try:
            ek.ek(os.remove, zonefile_tmp)
        except:
            logger.log(u'Unable to delete: %s' % zonefile_tmp, logger.ERROR)
            return

    if not helpers.copyFile(loc_tar, zonefile_tmp):
        return

    if not ek.ek(os.path.exists, zonefile_tmp):
        logger.log(u'Download of %s failed.' % zonefile_tmp, logger.ERROR)
        return

    new_hash = str(helpers.md5_for_file(zonefile_tmp))

    if zoneinfo_md5.upper() == new_hash.upper():
        logger.log(u'Updating timezone info with new one: %s' % new_zoneinfo,
                   logger.INFO)
        try:
            # remove the old zoneinfo file
            if cur_zoneinfo is not None:
                old_file = helpers.real_path(
                    ek.ek(
                        join,
                        ek.ek(os.path.dirname, lib.dateutil.zoneinfo.__file__),
                        cur_zoneinfo))
                if ek.ek(os.path.exists, old_file):
                    ek.ek(os.remove, old_file)
            # rename downloaded file
            ek.ek(os.rename, zonefile_tmp, zonefile)
            # load the new zoneinfo
            reload(lib.dateutil.zoneinfo)
            sb_timezone = tz.tzlocal()
        except:
            _remove_zoneinfo_failed(zonefile_tmp)
            return
    else:
        _remove_zoneinfo_failed(zonefile_tmp)
        logger.log(
            u'MD5 hash does not match: %s File: %s' %
            (zoneinfo_md5.upper(), new_hash.upper()), logger.ERROR)
        return
Beispiel #13
0
def _update_zoneinfo():
    global sb_timezone
    sb_timezone = tz.tzlocal()

    # TODO `git subtree pull` commands on updates

    loc_zv = helpers.real_path(ek.ek(join, ek.ek(os.path.dirname, __file__), u'../lib/network_timezones/zoneinfo.txt'))

    # Read version file
    try:
        with open(loc_zv, 'r') as file:
            data = file.read()
        if not data:
            raise

        # Filename of existing zoneinfo
        if lib.dateutil.zoneinfo.ZONEINFOFILE is not None:
            cur_zoneinfo = ek.ek(basename, lib.dateutil.zoneinfo.ZONEINFOFILE)
        else:
            cur_zoneinfo = None

        # Filename and hash of new zoneinfo
        (new_zoneinfo, zoneinfo_md5) = data.decode('utf-8').strip().rsplit(u' ')
    except Exception as e:
        logger.log(u'Crazy problem with zoneinfo: %s' % ex(e), logger.ERROR)
        return

    if (cur_zoneinfo is not None) and (new_zoneinfo == cur_zoneinfo):
        return

    # now load the new zoneinfo
    loc_tar = helpers.real_path(ek.ek(join, ek.ek(os.path.dirname, __file__), u'../lib/network_timezones/%s' % new_zoneinfo))

    zonefile = helpers.real_path(ek.ek(join, ek.ek(os.path.dirname, lib.dateutil.zoneinfo.__file__), new_zoneinfo))
    zonefile_tmp = re.sub(r'\.tar\.gz$', '.tmp', zonefile)

    if ek.ek(os.path.exists, zonefile_tmp):
        try:
            ek.ek(os.remove, zonefile_tmp)
        except:
            logger.log(u'Unable to delete: %s' % zonefile_tmp, logger.ERROR)
            return

    if not helpers.copyFile(loc_tar, zonefile_tmp):
        return

    if not ek.ek(os.path.exists, zonefile_tmp):
        logger.log(u'Download of %s failed.' % zonefile_tmp, logger.ERROR)
        return

    new_hash = str(helpers.md5_for_file(zonefile_tmp))

    if zoneinfo_md5.upper() == new_hash.upper():
        logger.log(u'Updating timezone info with new one: %s' % new_zoneinfo, logger.INFO)
        try:
            # remove the old zoneinfo file
            if cur_zoneinfo is not None:
                old_file = helpers.real_path(
                    ek.ek(join, ek.ek(os.path.dirname, lib.dateutil.zoneinfo.__file__), cur_zoneinfo))
                if ek.ek(os.path.exists, old_file):
                    ek.ek(os.remove, old_file)
            # rename downloaded file
            ek.ek(os.rename, zonefile_tmp, zonefile)
            # load the new zoneinfo
            reload(lib.dateutil.zoneinfo)
            sb_timezone = tz.tzlocal()
        except:
            _remove_zoneinfo_failed(zonefile_tmp)
            return
    else:
        _remove_zoneinfo_failed(zonefile_tmp)
        logger.log(u'MD5 hash does not match: %s File: %s' % (zoneinfo_md5.upper(), new_hash.upper()), logger.ERROR)
        return
Beispiel #14
0
 def restore_backup(self):
     if (ek.ek(os.path.isfile, self.backup_filename) and
             ek.ek(os.path.isfile, self.filename)):
         if self._delete_file(self.filename):
             copyFile(self.backup_filename, self.filename)
             self.remove_backup()
Beispiel #15
0
 def make_backup(self):
     copyFile(self.filename, self.backup_filename)