コード例 #1
0
def move_to_libray(item):
    # Copiamos el archivo a la biblioteca
    filetools.move(
        filetools.join(config.get_setting("downloadpath"),
                       item.downloadFilename),
        filetools.join(config.get_library_path(),
                       filetools.basename(item.downloadFilename)))
コード例 #2
0
def move_to_libray(item):
    try:
      from platformcode import library
    except:
      return
      
    # Copiamos el archivo a la biblioteca
    origen = filetools.join(config.get_setting("downloadpath"), item.downloadFilename)
    destino = filetools.join(config.get_library_path(), *filetools.split(item.downloadFilename))
    
    if not filetools.isdir(filetools.dirname(destino)):
      filetools.mkdir(filetools.dirname(destino))
    
    if filetools.isfile(destino) and filetools.isfile(origen) :
      filetools.remove(destino)

    if filetools.isfile(origen):
      filetools.move(origen, destino)
      if len(filetools.listdir(filetools.dirname(origen))) == 0: 
        filetools.rmdir(filetools.dirname(origen))
      
    else:
      logger.error("No se ha encontrado el archivo: %s" % origen)
    
    if filetools.isfile(destino):
      if item.contentType == "movie" and item.infoLabels["tmdb_id"]:
        library_item = Item(title="Descargado: %s" % item.downloadFilename, channel= "descargas", action="findvideos", infoLabels=item.infoLabels, url=destino)
        
        library.save_library_movie(library_item)
        
      elif item.contentType == "episode" and item.infoLabels["tmdb_id"]:
        library_item = Item(title="Descargado: %s" % item.downloadFilename, channel= "descargas", action="findvideos", infoLabels=item.infoLabels, url=destino)
        
        tvshow = Item(channel= "descargas", contentType="tvshow", infoLabels = {"tmdb_id": item.infoLabels["tmdb_id"]})
        library.save_library_tvshow(tvshow, [library_item])
コード例 #3
0
ファイル: torrent.py プロジェクト: fatshotty/addon
def rename(File):
    jsonPath = xbmc.translatePath(config.get_setting('downloadlistpath'))
    json = jsontools.load(open(filetools.join(jsonPath, File), "r").read())
    filePath = filetools.join(xbmc.translatePath(config.get_setting('downloadpath')), json['downloadFilename'])

    if json['infoLabels']['mediatype'] == 'movie':
        if filetools.isdir(filePath):
            extension = ''
            files = filetools.listdir(filePath)
            oldName = json['downloadFilename']
            newName = json['backupFilename']
            for f in files:
                ext = os.path.splitext(f)[-1]
                if ext in extensions_list: extension = ext
                filetools.rename(filetools.join(filePath, f), f.replace(oldName, newName))
            filetools.rename(filePath, newName)
            jsontools.update_node(filetools.join(newName, newName + extension), File, 'downloadFilename', jsonPath)

        else:
            oldName = json['downloadFilename']
            newName = json['backupFilename'] + os.path.splitext(oldName)[-1]
            filetools.rename(filePath, newName)
            jsontools.update_node(newName, File, 'downloadFilename', jsonPath)
    else:
        sep = '/' if filePath.lower().startswith("smb://") else os.sep
        FolderName = json['backupFilename'].split(sep)[0]
        Title = re.sub(r'(\s*\[[^\]]+\])', '', FolderName)
        if filetools.isdir(filePath):
            files = filetools.listdir(filePath)
            file_dict = {}
            for f in files:
                title = process_filename(f, Title, ext=False)
                ext = os.path.splitext(f)[-1]
                name = os.path.splitext(f)[0]
                if title not in file_dict and ext in extensions_list:
                    file_dict[title] = name

            for title, name in file_dict.items():
                for f in files:
                    if name in f:
                        filetools.rename(filetools.join(filePath, f), f.replace(name, title))

            filetools.rename(filePath, FolderName)
            jsontools.update_node(FolderName, File, 'downloadFilename', jsonPath)
        else:
            filename = filetools.split(filePath)[-1]
            title = process_filename(filename, Title)
            NewFolder = filetools.join(config.get_setting('downloadpath'), FolderName)
            if not filetools.isdir(NewFolder):
                filetools.mkdir(NewFolder)
            from_folder = filetools.join(config.get_setting('downloadpath'), filename)
            to_folder = filetools.join(config.get_setting('downloadpath'), FolderName, title)
            filetools.move(from_folder, to_folder)
            jsontools.update_node(filetools.join(FolderName, title), File, 'downloadFilename', jsonPath)
コード例 #4
0
ファイル: descargas.py プロジェクト: Dreancala/Prova
def move_to_libray(item):
    if not config.get_setting("library_move", "descargas") == True:
        return

    try:
        from core import library
    except:
        return

    # Copiamos el archivo a la biblioteca
    origen = filetools.join(config.get_setting("downloadpath"),
                            item.downloadFilename)
    destino = filetools.join(config.get_library_path(),
                             *filetools.split(item.downloadFilename))

    if not filetools.isdir(filetools.dirname(destino)):
        filetools.mkdir(filetools.dirname(destino))

    if filetools.isfile(destino) and filetools.isfile(origen):
        filetools.remove(destino)

    if filetools.isfile(origen):
        filetools.move(origen, destino)
        if len(filetools.listdir(filetools.dirname(origen))) == 0:
            filetools.rmdir(filetools.dirname(origen))

    else:
        logger.error("No se ha encontrado el archivo: %s" % origen)

    if filetools.isfile(destino):
        if item.contentType == "movie" and item.infoLabels["tmdb_id"]:
            library_item = Item(title="Scaricato: %s" % item.downloadFilename,
                                channel="descargas",
                                action="findvideos",
                                infoLabels=item.infoLabels,
                                url=item.downloadFilename)

            library.save_library_movie(library_item)

        elif item.contentType == "episode" and item.infoLabels["tmdb_id"]:
            library_item = Item(title="Scaricato: %s" % item.downloadFilename,
                                channel="descargas",
                                action="findvideos",
                                infoLabels=item.infoLabels,
                                url=item.downloadFilename)

            tvshow = Item(channel="descargas",
                          contentType="tvshow",
                          infoLabels={"tmdb_id": item.infoLabels["tmdb_id"]})
            library.save_library_tvshow(tvshow, [library_item])
コード例 #5
0
ファイル: backup.py プロジェクト: whiplash78/addon
def zip(dir, file):
    smb = False
    if file.lower().startswith('smb://'):
        temp = file
        file = filetools.join(temp_path, os.path.split(file)[-1])
        smb = True
    with ZipFile(filetools.file_open(file, 'wb', vfs=False), "w") as zf:
        abs_src = os.path.abspath(dir)
        for dirname, subdirs, files in os.walk(dir):
            for filename in files:
                absname = os.path.abspath(os.path.join(dirname, filename))
                arcname = absname[len(abs_src) + 1:]
                zf.write(absname, arcname)
        zf.close()
    if smb:
        filetools.move(file, temp)
コード例 #6
0
def move_to_libray(item):

    download_path = filetools.join(config.get_setting("downloadpath"), item.downloadFilename)
    library_path = filetools.join(config.get_library_path(), *filetools.split(item.downloadFilename))
    final_path = download_path
      
    if config.get_setting("library_add", "descargas") == True and config.get_setting("library_move", "descargas") == True:   
      if not filetools.isdir(filetools.dirname(library_path)):
        filetools.mkdir(filetools.dirname(library_path))
    
      if filetools.isfile(library_path) and filetools.isfile(download_path) :
        filetools.remove(library_path)

      if filetools.isfile(download_path):
        if filetools.move(download_path, library_path):
          final_path = library_path
          
        if len(filetools.listdir(filetools.dirname(download_path))) == 0: 
          filetools.rmdir(filetools.dirname(download_path))
          
    if config.get_setting("library_add", "descargas") == True: 
      if filetools.isfile(final_path):
        if item.contentType == "movie" and item.infoLabels["tmdb_id"]:
          library_item = Item(title="Descargado: %s" % item.downloadFilename, channel= "descargas", action="findvideos", infoLabels=item.infoLabels, url=final_path)
          library.save_library_movie(library_item)
          
        elif item.contentType == "episode" and item.infoLabels["tmdb_id"]:
          library_item = Item(title="Descargado: %s" % item.downloadFilename, channel= "descargas", action="findvideos", infoLabels=item.infoLabels, url=final_path)
          tvshow = Item(channel= "descargas", contentType="tvshow", infoLabels = {"tmdb_id": item.infoLabels["tmdb_id"]})
          library.save_library_tvshow(tvshow, [library_item])
コード例 #7
0
ファイル: updater.py プロジェクト: rrosajp/addon
def check(background=False):
    if not addon.getSetting('addon_update_enabled'):
        return False, False
    logger.info('Cerco aggiornamenti..')
    commits = loadCommits()
    if not commits:
        return False, False

    try:
        localCommitFile = open(os.path.join(addonDir, trackingFile), 'r+')
    except:
        calcCurrHash()
        localCommitFile = open(os.path.join(addonDir, trackingFile), 'r+')
    localCommitSha = localCommitFile.read()
    localCommitSha = localCommitSha.replace('\n', '')  # da testare
    logger.info('Commit locale: ' + localCommitSha)
    updated = False
    serviceChanged = False

    pos = None
    for n, c in enumerate(commits):
        if c['sha'] == localCommitSha:
            pos = n
            break
    else:
        # evitiamo che dia errore perchè il file è già in uso
        localCommitFile.close()
        calcCurrHash()
        return True, False

    if pos > 0:
        changelog = ''
        poFilesChanged = False
        try:
            for c in reversed(commits[:pos]):
                commit = urllib.urlopen(c['url']).read()
                commitJson = json.loads(commit)
                # evitiamo di applicare i merge commit
                if 'Merge' in commitJson['commit']['message']:
                    continue
                logger.info('aggiornando a ' + commitJson['sha'])

                # major update
                if len(commitJson['files']) > 50:
                    localCommitFile.close()
                    c['sha'] = updateFromZip('Aggiornamento in corso...')
                    localCommitFile = open(
                        os.path.join(
                            xbmc.translatePath("special://home/addons/"),
                            'plugin.video.kod', trackingFile),
                        'w')  # il file di tracking viene eliminato, lo ricreo
                    changelog += commitJson['commit']['message'] + "\n"
                    poFilesChanged = True
                    serviceChanged = True
                    break

                patch_url = commitJson['html_url'] + '.patch'
                logger.info('applicando ' + patch_url)
                from lib import patch
                patchOk = patch.fromurl(patch_url).apply(root=addonDir)

                for file in commitJson['files']:
                    if file["filename"] == trackingFile:  # il file di tracking non si modifica
                        continue
                    else:
                        logger.info(file["filename"])
                        if 'resources/language' in file["filename"]:
                            poFilesChanged = True
                        if 'service.py' in file["filename"]:
                            serviceChanged = True
                        if (file['status'] == 'modified' and 'patch'
                                not in file) or file['status'] == 'added' or (
                                    file['status'] == 'modified'
                                    and not patchOk):
                            # è un file NON testuale che è stato modificato, oppure è un file nuovo (la libreria non supporta la creazione di un nuovo file)
                            # lo devo scaricare
                            filename = os.path.join(addonDir, file['filename'])
                            dirname = os.path.dirname(filename)
                            if not (filetools.isfile(
                                    os.path.join(addonDir, file['filename']))
                                    and getSha(filename) == file['sha']):
                                logger.info('scaricando ' + file['raw_url'])
                                if not os.path.exists(dirname):
                                    os.makedirs(dirname)
                                urllib.urlretrieve(file['raw_url'], filename)
                        elif file['status'] == 'removed':
                            remove(os.path.join(addonDir, file["filename"]))
                        elif file['status'] == 'renamed':
                            # se non è già applicato
                            if not (filetools.isfile(
                                    os.path.join(addonDir, file['filename']))
                                    and getSha(
                                        os.path.join(addonDir,
                                                     file['filename']))
                                    == file['sha']):
                                dirs = file['filename'].split('/')
                                for d in dirs[:-1]:
                                    if not filetools.isdir(
                                            os.path.join(addonDir, d)):
                                        filetools.mkdir(
                                            os.path.join(addonDir, d))
                                filetools.move(
                                    os.path.join(addonDir,
                                                 file['previous_filename']),
                                    os.path.join(addonDir, file['filename']))
                changelog += commitJson['commit']['message'] + "\n"
        except:
            import traceback
            logger.error(traceback.format_exc())
            # fallback
            localCommitFile.close()
            c['sha'] = updateFromZip('Aggiornamento in corso...')
            localCommitFile = open(
                os.path.join(xbmc.translatePath("special://home/addons/"),
                             'plugin.video.kod', trackingFile),
                'w')  # il file di tracking viene eliminato, lo ricreo

        localCommitFile.seek(0)
        localCommitFile.truncate()
        localCommitFile.writelines(c['sha'])
        localCommitFile.close()
        xbmc.executebuiltin("UpdateLocalAddons")
        if poFilesChanged:
            refreshLang()
            xbmc.sleep(1000)
        updated = True

        if addon.getSetting("addon_update_message"):
            if background:
                platformtools.dialog_notification(
                    config.get_localized_string(20000),
                    config.get_localized_string(80040) % commits[0]['sha'][:7],
                    time=3000,
                    sound=False)
                try:
                    with open(config.changelogFile, 'a+') as fileC:
                        fileC.write(changelog)
                except:
                    import traceback
                    logger.error(traceback.format_exc())
            elif changelog:
                platformtools.dialog_ok(
                    config.get_localized_string(20000),
                    config.get_localized_string(80041) + changelog)
    else:
        logger.info('Nessun nuovo aggiornamento')

    return updated, serviceChanged
コード例 #8
0
def move_to_libray(item):
    if item.contentType == 'movie':
        FOLDER = FOLDER_MOVIES
        path_title = "%s [%s]" % (item.contentTitle.strip(),
                                  item.infoLabels['IMDBNumber'])
        move_path = filetools.join(config.get_videolibrary_path(), FOLDER,
                                   path_title)

    else:
        FOLDER = FOLDER_TVSHOWS
        path_title = "%s [%s]" % (item.contentSerieName,
                                  item.infoLabels['IMDBNumber'])
        move_path = filetools.join(config.get_videolibrary_path(), FOLDER)

    download_path = filetools.join(config.get_setting("downloadpath"),
                                   item.downloadFilename)
    library_path = filetools.join(move_path,
                                  *filetools.split(item.downloadFilename))
    final_path = download_path

    if config.get_setting("library_add",
                          "downloads") == True and config.get_setting(
                              "library_move", "downloads") == True:
        if not filetools.isdir(filetools.dirname(library_path)):
            filetools.mkdir(filetools.dirname(library_path))

        if filetools.isfile(library_path) and filetools.isfile(download_path):
            filetools.remove(library_path)

        if filetools.isfile(download_path):
            if filetools.move(download_path, library_path):
                final_path = library_path

            if len(filetools.listdir(filetools.dirname(download_path))) == 0:
                filetools.rmdir(filetools.dirname(download_path))

        logger.info('ITEM = ' + str(item))
        name = item.contentTitle if item.contentType == 'movie' else str(
            item.infoLabels['season']) + 'x' + str(
                item.infoLabels['episode']).zfill(2)
        list_item = os.listdir(
            filetools.join(config.get_videolibrary_path(), FOLDER, path_title))

        clean = False
        for File in list_item:
            filename = File.lower()
            name = name.lower()
            if filename.startswith(name) and (filename.endswith('.strm')
                                              or filename.endswith('.json')
                                              or filename.endswith('.nfo')):
                clean = True
                logger.info('Delete File: ' + str(
                    os.path.join(config.get_videolibrary_path(), FOLDER,
                                 path_title, File)))
                os.remove(
                    os.path.join(config.get_videolibrary_path(), FOLDER,
                                 path_title, File))
        from platformcode import xbmc_videolibrary

        xbmc_videolibrary.update(FOLDER)
        if clean == True:
            import xbmc
            while xbmc.getCondVisibility('Library.IsScanningVideo()'):
                xbmc.sleep(500)
            xbmc_videolibrary.clean()

    if config.get_setting("library_add",
                          "downloads") == True and config.get_setting(
                              "library_move", "downloads") == False:
        if filetools.isfile(final_path):
            if item.contentType == "movie" and item.infoLabels["tmdb_id"]:
                library_item = Item(title=config.get_localized_string(70228) %
                                    item.downloadFilename,
                                    channel="downloads",
                                    action="findvideos",
                                    infoLabels=item.infoLabels,
                                    url=final_path)
                videolibrarytools.save_movie(library_item)

            elif item.contentType == "episode" and item.infoLabels["tmdb_id"]:
                library_item = Item(title=config.get_localized_string(70228) %
                                    item.downloadFilename,
                                    channel="downloads",
                                    action="findvideos",
                                    infoLabels=item.infoLabels,
                                    url=final_path)
                tvshow = Item(
                    channel="downloads",
                    contentType="tvshow",
                    infoLabels={"tmdb_id": item.infoLabels["tmdb_id"]})
                videolibrarytools.save_tvshow(tvshow, [library_item])
コード例 #9
0
ファイル: updater.py プロジェクト: cesarebattisti/addon
def check_addon_init():
    if not addon.getSetting('addon_update_enabled'):
        return False
    logger.info('Cerco aggiornamenti..')
    commits = loadCommits()

    try:
        localCommitFile = open(addonDir + trackingFile, 'r+')
    except:
        calcCurrHash()
        localCommitFile = open(addonDir + trackingFile, 'r+')
    localCommitSha = localCommitFile.read()
    localCommitSha = localCommitSha.replace('\n', '')  # da testare
    logger.info('Commit locale: ' + localCommitSha)
    updated = False

    pos = None
    for n, c in enumerate(commits):
        if c['sha'] == localCommitSha:
            pos = n
            break
    else:
        # evitiamo che dia errore perchè il file è già in uso
        localCommitFile.close()
        updateFromZip()
        return True

    if pos > 0:
        changelog = ''
        nCommitApplied = 0
        for c in reversed(commits[:pos]):
            commit = httptools.downloadpage(c['url']).data
            commitJson = json.loads(commit)
            logger.info('aggiornando a' + commitJson['sha'])
            alreadyApplied = True

            for file in commitJson['files']:
                if file["filename"] == trackingFile:  # il file di tracking non si modifica
                    continue
                else:
                    logger.info(file["filename"])
                    if file['status'] == 'modified' or file[
                            'status'] == 'added':
                        if 'patch' in file:
                            text = ""
                            try:
                                localFile = open(addonDir + file["filename"],
                                                 'r+')
                                for line in localFile:
                                    text += line
                            except IOError:  # nuovo file
                                localFile = open(addonDir + file["filename"],
                                                 'w')

                            patched = apply_patch(text, (file['patch'] +
                                                         '\n').encode('utf-8'))
                            if patched != text:  # non eseguo se già applicata (es. scaricato zip da github)
                                if getSha(patched) == file['sha']:
                                    localFile.seek(0)
                                    localFile.truncate()
                                    localFile.writelines(patched)
                                    localFile.close()
                                    alreadyApplied = False
                                else:  # nel caso ci siano stati problemi
                                    logger.info(
                                        'lo sha non corrisponde, scarico il file'
                                    )
                                    downloadtools.downloadfile(
                                        file['raw_url'],
                                        addonDir + file['filename'],
                                        silent=True,
                                        continuar=True)
                        else:  # è un file NON testuale, lo devo scaricare
                            # se non è già applicato
                            if not (filetools.isfile(addonDir +
                                                     file['filename'])
                                    and getSha(
                                        filetools.read(addonDir +
                                                       file['filename']) ==
                                        file['sha'])):
                                downloadtools.downloadfile(file['raw_url'],
                                                           addonDir +
                                                           file['filename'],
                                                           silent=True,
                                                           continuar=True)
                                alreadyApplied = False
                    elif file['status'] == 'removed':
                        try:
                            filetools.remove(addonDir + file["filename"])
                            alreadyApplied = False
                        except:
                            pass
                    elif file['status'] == 'renamed':
                        # se non è già applicato
                        if not (filetools.isfile(addonDir + file['filename'])
                                and getSha(
                                    filetools.read(addonDir + file['filename'])
                                    == file['sha'])):
                            dirs = file['filename'].split('/')
                            for d in dirs[:-1]:
                                if not filetools.isdir(addonDir + d):
                                    filetools.mkdir(addonDir + d)
                            filetools.move(
                                addonDir + file['previous_filename'],
                                addonDir + file['filename'])
                            alreadyApplied = False
            if not alreadyApplied:  # non mando notifica se già applicata (es. scaricato zip da github)
                changelog += commitJson['commit']['message'] + " | "
                nCommitApplied += 1
        if addon.getSetting("addon_update_message"):
            time = nCommitApplied * 2000 if nCommitApplied < 10 else 20000
            platformtools.dialog_notification('Kodi on Demand', changelog,
                                              time)

        localCommitFile.seek(0)
        localCommitFile.truncate()
        localCommitFile.writelines(c['sha'])
        localCommitFile.close()

    else:
        logger.info('Nessun nuovo aggiornamento')

    return updated
コード例 #10
0
def check(background=False):
    if not addon.getSetting('addon_update_enabled'):
        return False, False
    logger.info('Cerco aggiornamenti..')
    commits = loadCommits()
    if not commits:
        return False, False

    try:
        localCommitFile = open(os.path.join(addonDir, trackingFile), 'r+')
    except:
        calcCurrHash()
        localCommitFile = open(os.path.join(addonDir, trackingFile), 'r+')
    localCommitSha = localCommitFile.read()
    localCommitSha = localCommitSha.replace('\n', '')  # da testare
    logger.info('Commit locale: ' + localCommitSha)
    updated = False
    serviceChanged = False

    pos = None
    for n, c in enumerate(commits):
        if c['sha'] == localCommitSha:
            pos = n
            break
    else:
        # evitiamo che dia errore perchè il file è già in uso
        localCommitFile.close()
        calcCurrHash()
        return True, False

    if pos > 0:
        changelog = ''
        poFilesChanged = False
        try:
            for c in reversed(commits[:pos]):
                commit = urllib.urlopen(c['url']).read()
                commitJson = json.loads(commit)
                # evitiamo di applicare i merge commit
                if 'Merge' in commitJson['commit']['message']:
                    continue
                logger.info('aggiornando a ' + commitJson['sha'])
                alreadyApplied = True

                # major update
                if len(commitJson['files']) > 50:
                    localCommitFile.close()
                    c['sha'] = updateFromZip('Aggiornamento in corso...')
                    localCommitFile = open(
                        os.path.join(
                            xbmc.translatePath("special://home/addons/"),
                            'plugin.video.kod', trackingFile),
                        'w')  # il file di tracking viene eliminato, lo ricreo
                    changelog += commitJson['commit']['message'] + "\n"
                    poFilesChanged = True
                    break

                for file in commitJson['files']:
                    if file["filename"] == trackingFile:  # il file di tracking non si modifica
                        continue
                    else:
                        logger.info(file["filename"])
                        if 'resources/language' in file["filename"]:
                            poFilesChanged = True
                        if 'service.py' in file["filename"]:
                            serviceChanged = True
                        if file['status'] == 'modified' or file[
                                'status'] == 'added':
                            if 'patch' in file:
                                text = ""
                                try:
                                    localFile = io.open(os.path.join(
                                        addonDir, file["filename"]),
                                                        'r+',
                                                        encoding="utf8")
                                    text = localFile.read()
                                    if not PY3:
                                        text = text.decode('utf-8')
                                except IOError:  # nuovo file
                                    # crea le cartelle se non esistono
                                    dirname = os.path.dirname(
                                        os.path.join(addonDir,
                                                     file["filename"]))
                                    if not os.path.exists(dirname):
                                        os.makedirs(dirname)

                                    localFile = io.open(os.path.join(
                                        addonDir, file["filename"]),
                                                        'w',
                                                        encoding="utf8")

                                patched = apply_patch(text,
                                                      (file['patch'] +
                                                       '\n').encode('utf-8'))
                                if patched != text:  # non eseguo se già applicata (es. scaricato zip da github)
                                    alreadyApplied = False
                                    if getShaStr(patched) == file['sha']:
                                        localFile.seek(0)
                                        localFile.truncate()
                                        localFile.writelines(patched)
                                        localFile.close()
                                    else:  # nel caso ci siano stati problemi
                                        logger.info(
                                            'lo sha non corrisponde, scarico il file'
                                        )
                                        localFile.close()
                                        urllib.urlretrieve(
                                            file['raw_url'],
                                            os.path.join(
                                                addonDir, file['filename']))
                            else:  # è un file NON testuale, lo devo scaricare
                                # se non è già applicato
                                filename = os.path.join(
                                    addonDir, file['filename'])
                                dirname = os.path.dirname(filename)
                                if not (filetools.isfile(
                                        os.path.join(addonDir,
                                                     file['filename']))
                                        and getSha(filename) == file['sha']):
                                    if not os.path.exists(dirname):
                                        os.makedirs(dirname)
                                    urllib.urlretrieve(file['raw_url'],
                                                       filename)
                                    alreadyApplied = False
                        elif file['status'] == 'removed':
                            remove(os.path.join(addonDir, file["filename"]))
                            alreadyApplied = False
                        elif file['status'] == 'renamed':
                            # se non è già applicato
                            if not (filetools.isfile(
                                    os.path.join(addonDir, file['filename']))
                                    and getSha(
                                        os.path.join(addonDir,
                                                     file['filename']))
                                    == file['sha']):
                                dirs = file['filename'].split('/')
                                for d in dirs[:-1]:
                                    if not filetools.isdir(
                                            os.path.join(addonDir, d)):
                                        filetools.mkdir(
                                            os.path.join(addonDir, d))
                                filetools.move(
                                    os.path.join(addonDir,
                                                 file['previous_filename']),
                                    os.path.join(addonDir, file['filename']))
                                alreadyApplied = False
                if not alreadyApplied:  # non mando notifica se già applicata (es. scaricato zip da github)
                    changelog += commitJson['commit']['message'] + "\n"
        except:
            import traceback
            logger.error(traceback.format_exc())
            # fallback
            localCommitFile.close()
            c['sha'] = updateFromZip('Aggiornamento in corso...')
            localCommitFile = open(
                os.path.join(xbmc.translatePath("special://home/addons/"),
                             'plugin.video.kod', trackingFile),
                'w')  # il file di tracking viene eliminato, lo ricreo
        if addon.getSetting("addon_update_message"):
            if background:
                platformtools.dialog_notification(
                    config.get_localized_string(20000),
                    config.get_localized_string(80040) % commits[0]['sha'][:7],
                    time=3000,
                    sound=False)
                with open(xbmc.translatePath(changelogFile), 'a+') as fileC:
                    fileC.write(changelog)
            elif changelog:
                platformtools.dialog_ok(
                    config.get_localized_string(20000),
                    config.get_localized_string(80041) + changelog)

        localCommitFile.seek(0)
        localCommitFile.truncate()
        localCommitFile.writelines(c['sha'])
        localCommitFile.close()
        xbmc.executebuiltin("UpdateLocalAddons")
        if poFilesChanged:
            refreshLang()
        updated = True
    else:
        logger.info('Nessun nuovo aggiornamento')

    return updated, serviceChanged
コード例 #11
0
ファイル: descargas.py プロジェクト: jurrKodi/pelisalacarta
def move_to_libray(item):
    # Copiamos el archivo a la biblioteca
    filetools.move(filetools.join(config.get_setting("downloadpath"), item.downloadFilename),
                   filetools.join(config.get_library_path(), filetools.basename(item.downloadFilename)))