예제 #1
0
def copy_inside_dir(dirname,
                    destination,
                    overwrite=True,
                    progressBar=None,
                    percentage=100):
    list_dir = os.listdir(dirname)
    for file in list_dir:
        src = os.path.join(dirname, file)
        dst = os.path.join(destination, file)
        if os.path.isfile(src):
            if not os.path.isdir(os.path.dirname(dst)):
                os.makedirs(os.path.dirname(dst))
            if not overwrite and os.path.isfile(dst):
                os.unlink(dst)
            shutil2.copyfile(src,
                             dst,
                             overwrite=overwrite,
                             progressBar=progressBar,
                             percentage=percentage)
        elif os.path.isdir(src):
            if not overwrite and os.path.isdir(dst):
                shutil2.rmtree(dst)
            shutil2.copytree(src,
                             dst,
                             overwrite=overwrite,
                             progressBar=progressBar,
                             percentage=percentage)
예제 #2
0
 def copyInsideDir(self,
                   r_dir_src,
                   r_dir_dest,
                   overwrite=True,
                   progressBar=None):
     """
     Copy the content a directory to a new location
     """
     dir_src = xbmc.makeLegalFilename(r_dir_src)
     dir_dest = xbmc.makeLegalFilename(r_dir_dest)
     list_dir = os.listdir(dir_src)
     for file in list_dir:
         src = os.path.join(dir_src, file)
         dst = os.path.join(dir_dest, file)
         if os.path.isfile(src):
             if not os.path.isdir(os.path.dirname(dst)):
                 os.makedirs(os.path.dirname(dst))
             if not overwrite and os.path.isfile(dst):
                 os.unlink(dst)
             shutil2.copyfile(src,
                              dst,
                              overwrite=overwrite,
                              progressBar=progressBar,
                              curPercent=100)
         elif os.path.isdir(src):
             if not overwrite and os.path.isdir(dst):
                 shutil2.rmtree(dst)
             shutil2.copytree(src,
                              dst,
                              overwrite=overwrite,
                              progressBar=progressBar,
                              curPercent=100)
예제 #3
0
def Main():
    try:
        if configs[ "XBMC_HOME_PATH" ].lower() != "q:\\":
            svn_rev, build_zip = parse_paths_txt()
            if bool( build_zip ) and os.path.exists( build_zip ):
                configs[ "SVN_REV" ] = svn_rev #"27495"
                configs[ "BUILD_ZIP" ] = build_zip #"G:\WebDownload\XBMC_Xbox_27495.zip"
                configs[ "LISTITEMS_UPDATE" ] = listitems_update % configs

            configs[ "LISTITEMS_CLEANER" ] = listitems_cleaner % configs
            conf = base_xml % configs
            file( os.path.join( UPDATER_PATH, "update.xml" ), "w" ).write( conf )

            try:
                default_save = os.path.join( "E:\\UDATA", "9e115330", "0064122817A8" )
                #if not os.path.exists( default_save ): os.makedirs( default_save )
                #from shutil import copy
                import shutil2
                shutil2.copytree( os.path.join( UPDATER_PATH, "media", "UDATA" ), "E:\\UDATA", overwrite=True )
                #copy( os.path.join( UPDATER_PATH, "skin", "Confluence", "UXSplash.jpg" ), os.path.join( default_save, "Splash.jpg" ) )
                if os.path.exists( "X:\\0064122817A8" ): 
                    shutil2.copy( os.path.join( default_save, "Splash.jpg" ), os.path.join( "X:\\0064122817A8", "Splash.jpg" ) )
            except:
                print_exc()

            xbmc.executebuiltin( "XBMC.RunXBE(%s)" % os.path.join( UPDATER_PATH, "updater.xbe" ) )
            return
    except:
        print_exc()
    print "impossible de faire la mise a jour!!!"
    def copyInThread(self, src, des, IsADir):

        if IsADir:

            shutil2.copytree(src, des, isTagInstalled=checkTag)

        else:

            shutil2.copy2(src, des)
예제 #5
0
 def copyDir(self, r_dir_src, r_dir_dest, overwrite=True, progressBar=None):
     """
     Copy a directory to a new location
     """
     # dir_src  = xbmc.makeLegalFilename( r_dir_src )
     # dir_dest = xbmc.makeLegalFilename( r_dir_dest )
     dir_src = r_dir_src
     dir_dest = r_dir_dest
     if not overwrite and os.path.isdir(dir_dest):
         shutil2.rmtree(dir_dest)
     shutil2.copytree(dir_src, dir_dest, overwrite=overwrite, progressBar=progressBar, curPercent=100)
예제 #6
0
def copy_dir(dirname,
             destination,
             overwrite=True,
             progressBar=None,
             percentage=100):
    if not overwrite and os.path.isdir(destination):
        shutil2.rmtree(destination)
    shutil2.copytree(dirname,
                     destination,
                     overwrite=overwrite,
                     progressBar=progressBar,
                     percentage=percentage)
예제 #7
0
 def copyDir(self, r_dir_src, r_dir_dest, overwrite=True, progressBar=None):
     """
     Copy a directory to a new location
     """
     #dir_src  = xbmc.makeLegalFilename( r_dir_src )
     #dir_dest = xbmc.makeLegalFilename( r_dir_dest )
     dir_src = r_dir_src
     dir_dest = r_dir_dest
     if not overwrite and os.path.isdir(dir_dest):
         shutil2.rmtree(dir_dest)
     shutil2.copytree(dir_src,
                      dir_dest,
                      overwrite=overwrite,
                      progressBar=progressBar,
                      curPercent=100)
예제 #8
0
def copy_inside_dir( dirname, destination, overwrite=True, progressBar=None, percentage=100 ):
    list_dir = os.listdir( dirname )
    for file in list_dir:
        src = os.path.join( dirname, file )
        dst = os.path.join( destination, file )
        if os.path.isfile( src ):
            if not os.path.isdir( os.path.dirname( dst ) ):
                os.makedirs( os.path.dirname( dst ) )
            if not overwrite and os.path.isfile( dst ):
                os.unlink( dst )
            shutil2.copyfile( src, dst, overwrite=overwrite, progressBar=progressBar, percentage=percentage )
        elif os.path.isdir( src ):
            if not overwrite and os.path.isdir( dst ):
                shutil2.rmtree( dst )
            shutil2.copytree( src, dst, overwrite=overwrite, progressBar=progressBar, percentage=percentage )
예제 #9
0
 def copyInsideDir(self, r_dir_src, r_dir_dest, overwrite=True, progressBar=None):
     """
     Copy the content a directory to a new location
     """
     dir_src = xbmc.makeLegalFilename(r_dir_src)
     dir_dest = xbmc.makeLegalFilename(r_dir_dest)
     list_dir = os.listdir(dir_src)
     for file in list_dir:
         src = os.path.join(dir_src, file)
         dst = os.path.join(dir_dest, file)
         if os.path.isfile(src):
             if not os.path.isdir(os.path.dirname(dst)):
                 os.makedirs(os.path.dirname(dst))
             if not overwrite and os.path.isfile(dst):
                 os.unlink(dst)
             shutil2.copyfile(src, dst, overwrite=overwrite, progressBar=progressBar, curPercent=100)
         elif os.path.isdir(src):
             if not overwrite and os.path.isdir(dst):
                 shutil2.rmtree(dst)
             shutil2.copytree(src, dst, overwrite=overwrite, progressBar=progressBar, curPercent=100)
예제 #10
0
def Main():
    try:
        if configs["XBMC_HOME_PATH"].lower() != "q:\\":
            svn_rev, build_zip = parse_paths_txt()
            if bool(build_zip) and os.path.exists(build_zip):
                configs["SVN_REV"] = svn_rev  #"27495"
                configs[
                    "BUILD_ZIP"] = build_zip  #"G:\WebDownload\XBMC_Xbox_27495.zip"
                configs["LISTITEMS_UPDATE"] = listitems_update % configs

            configs["LISTITEMS_CLEANER"] = listitems_cleaner % configs
            conf = base_xml % configs
            file(os.path.join(UPDATER_PATH, "update.xml"), "w").write(conf)

            try:
                default_save = os.path.join("E:\\UDATA", "9e115330",
                                            "0064122817A8")
                #if not os.path.exists( default_save ): os.makedirs( default_save )
                #from shutil import copy
                import shutil2
                shutil2.copytree(os.path.join(UPDATER_PATH, "media", "UDATA"),
                                 "E:\\UDATA",
                                 overwrite=True)
                #copy( os.path.join( UPDATER_PATH, "skin", "Confluence", "UXSplash.jpg" ), os.path.join( default_save, "Splash.jpg" ) )
                if os.path.exists("X:\\0064122817A8"):
                    shutil2.copy(
                        os.path.join(default_save, "Splash.jpg"),
                        os.path.join("X:\\0064122817A8", "Splash.jpg"))
            except:
                print_exc()

            xbmc.executebuiltin("XBMC.RunXBE(%s)" %
                                os.path.join(UPDATER_PATH, "updater.xbe"))
            return
    except:
        print_exc()
    print "impossible de faire la mise a jour!!!"
예제 #11
0
def copy_dir( dirname, destination, overwrite=True, progressBar=None, percentage=100 ):
    if not overwrite and os.path.isdir( destination ):
        shutil2.rmtree( destination )
    shutil2.copytree( dirname, destination, overwrite=overwrite, progressBar=progressBar, percentage=percentage )
예제 #12
0
    def _show_context_menu(self):
        self.index = self.getCurrentListPosition()

        try:
            # On va ici afficher un menu des options du gestionnaire de fichiers
            item_path = self.currentItemList[
                self.index - self.
                pardir_not_hidden].local_path  # On extrait le chemin de l'item
            item_basename = os.path.basename(item_path)

            if ((self.getListItem(self.index).getProperty("Running") == "true")
                    or self.curListType == TYPE_ROOT
                    or self.curListType == TYPE_PLUGIN
                    or self.curListType == TYPE_SCRAPER):
                # Options list for skin or add-ons currently in use
                buttons = {1003: _(161), 1005: _(185), 1006: _(1002)}
            elif (self.curListType
                  == TYPE_SCRIPT) or (self.curListType
                                      in self.pluginDisplayList):
                # Options list for plugins, scripts and scrapers
                buttons = {
                    1000: _(160),
                    1001: _(157),
                    1002: _(156),
                    1003: _(161),
                    1004: _(162),
                    1005: _(185),
                    1006: _(1002)
                }
            else:
                # Options list for skins et scrapers
                buttons = {
                    1001: _(157),
                    1002: _(156),
                    1003: _(161),
                    1004: _(162),
                    1005: _(185),
                    1006: _(1002)
                }

            if os.path.exists(os.path.join(item_path, "description.xml")):
                buttons.update({999: _(1001)})

            from DialogContextMenu import show_context_menu
            selected = show_context_menu(buttons, self.get_view_mode())
            del show_context_menu

            if selected == 999:
                import infos
                infos.show_info(item_path)
                del infos

            elif selected == 1000:  # Executer/Lancer
                if (self.curListType in self.pluginDisplayList):
                    # Cas d'un sous-plugin (video, musique ...)
                    # window id's : http://xbmc.org/wiki/?title=Window_IDs
                    if (self.curListType == TYPE_PLUGIN_VIDEO):
                        command = "XBMC.ActivateWindow(10025,plugin://video/%s/)" % (
                            item_basename, )
                    elif (self.curListType == TYPE_PLUGIN_MUSIC):
                        command = "XBMC.ActivateWindow(10502,plugin://music/%s/)" % (
                            item_basename, )
                    elif (self.curListType == TYPE_PLUGIN_PROGRAMS):
                        command = "XBMC.ActivateWindow(10001,plugin://programs/%s/)" % (
                            item_basename, )
                    elif (self.curListType == TYPE_PLUGIN_PICTURES):
                        command = "XBMC.ActivateWindow(10002,plugin://pictures/%s/)" % (
                            item_basename, )
                    #TODO: case of Weather plugin
                elif (self.curListType == TYPE_SCRIPT):
                    command = "XBMC.RunScript(%s)" % (os.path.join(
                        item_path, "default.py"), )

                #on ferme le script en court pour pas generer des conflits
                self._close_dialog()
                self._close_script()
                #maintenant qu'il y a plus de conflit possible, on execute la command
                xbmc.executebuiltin(command)

            elif selected == 1001:  # Renommer
                # Renommer l'element
                item_dirname = os.path.dirname(item_path)

                if (self.curListType
                        in [TYPE_SCRAPER_MUSIC, TYPE_SCRAPER_VIDEO]):
                    icon_path = self.currentItemList[
                        self.index - self.
                        pardir_not_hidden].thumb  # On extrait le chemin de l'icone
                    icon_basename = os.path.basename(icon_path)
                    default_basename = os.path.splitext(item_basename)[0]
                    keyboard = xbmc.Keyboard(default_basename, _(154))
                    keyboard.doModal()
                    if (keyboard.isConfirmed()):
                        inputText = keyboard.getText()
                        # ne renomme pas l'item si le nouveau nom est le meme que le default
                        if default_basename != inputText:
                            self.fileMgr.renameItem(item_dirname,
                                                    item_basename,
                                                    inputText + '.xml')
                            if icon_path != get_thumb(self.curListType):
                                self.fileMgr.renameItem(
                                    item_dirname, icon_basename,
                                    icon_basename.replace(
                                        os.path.splitext(icon_basename)[0],
                                        inputText))
                            xbmcgui.Dialog().ok(_(155), inputText)
                            self.updateDataAndList()
                else:
                    keyboard = xbmc.Keyboard(item_basename, _(154))
                    keyboard.doModal()
                    if (keyboard.isConfirmed()):
                        inputText = keyboard.getText()
                        # ne renomme pas l'item si le nouveau nom est le meme que le default
                        if item_basename != inputText:
                            self.fileMgr.renameItem(item_dirname,
                                                    item_basename, inputText)
                            xbmcgui.Dialog().ok(_(155), inputText)
                            self.updateDataAndList()

            elif selected == 1002:
                # Supprimer l'element
                if (self.curListType
                        in [TYPE_SCRAPER_MUSIC, TYPE_SCRAPER_VIDEO]):
                    icon_path = self.currentItemList[
                        self.index - self.
                        pardir_not_hidden].thumb  # On extrait le chemin de l'icone
                    item_shortname = os.path.splitext(item_basename)[
                        0]  # Sans extension
                    if xbmcgui.Dialog().yesno(
                            _(158) % item_shortname,
                            _(159) % item_shortname):
                        self.fileMgr.deleteItem(item_path)
                        if icon_path != get_thumb(self.curListType):
                            self.fileMgr.deleteItem(icon_path)
                        self.updateDataAndList()
                else:
                    if xbmcgui.Dialog().yesno(
                            _(158) % item_basename,
                            _(159) % item_basename):
                        self.fileMgr.deleteItem(item_path)
                        self.updateDataAndList()

            elif selected == 1003:
                # copier l'element
                if (self.curListType
                        in [TYPE_SCRAPER_MUSIC, TYPE_SCRAPER_VIDEO]):
                    #TODO : A optimiser, on doit pouvoir faire mieux
                    item_dirname = os.path.dirname(item_path)
                    item_shortname = os.path.splitext(item_basename)[
                        0]  # Sans extension
                    icon_path = self.currentItemList[
                        self.index - self.
                        pardir_not_hidden].thumb  # On extrait le chemin de l'icone
                    icon_ext = os.path.splitext(os.path.basename(icon_path))[1]
                    new_path = xbmcgui.Dialog().browse(3,
                                                       _(167) % item_shortname,
                                                       "files")
                    if bool(new_path):
                        src = os.path.normpath(
                            os.path.join(item_dirname, item_shortname))
                        dst = os.path.normpath(
                            os.path.join(new_path, item_shortname))
                        if xbmcgui.Dialog().yesno(_(163), _(165), src, dst):
                            DIALOG_PROGRESS.create(_(176),
                                                   _(178) + src,
                                                   _(179) + dst, _(110))
                            try:
                                shutil2.copy(src + ".xml",
                                             dst + ".xml",
                                             reportcopy=copy_func,
                                             overwrite=True)
                                if os.path.exists(src + icon_ext):
                                    shutil2.copy(src + icon_ext,
                                                 dst + icon_ext,
                                                 reportcopy=copy_func,
                                                 overwrite=True)
                            except:
                                xbmcgui.Dialog().ok(_(169), _(170), _(171))
                                print_exc()
                            #self.updateDataAndList()
                            DIALOG_PROGRESS.close()
                else:
                    new_path = xbmcgui.Dialog().browse(3,
                                                       _(167) % item_basename,
                                                       "files")
                    if bool(new_path):
                        src = os.path.normpath(item_path)
                        dst = os.path.normpath(
                            os.path.join(new_path, item_basename))
                        if xbmcgui.Dialog().yesno(_(163), _(165), src, dst):
                            DIALOG_PROGRESS.create(_(176),
                                                   _(178) + src,
                                                   _(179) + dst, _(110))
                            try:
                                if os.path.isdir(src):
                                    if not os.path.isdir(os.path.dirname(dst)):
                                        os.makedirs(os.path.dirname(dst))
                                    shutil2.copytree(src,
                                                     dst,
                                                     reportcopy=copy_func,
                                                     overwrite=True)
                                else:
                                    shutil2.copy(src,
                                                 dst,
                                                 reportcopy=copy_func,
                                                 overwrite=True)
                            except:
                                xbmcgui.Dialog().ok(_(169), _(170), _(171))
                                print_exc()
                            #self.updateDataAndList()
                            DIALOG_PROGRESS.close()

            elif selected == 1004:
                # deplacer l'element
                if (self.curListType
                        in [TYPE_SCRAPER_MUSIC, TYPE_SCRAPER_VIDEO]):
                    #TODO : A optimiser, on doit pouvoir faire mieux
                    item_dirname = os.path.dirname(item_path)
                    item_shortname = os.path.splitext(item_basename)[
                        0]  # Sans extension
                    icon_path = self.currentItemList[
                        self.index - self.
                        pardir_not_hidden].thumb  # On extrait le chemin de l'icone
                    icon_ext = os.path.splitext(os.path.basename(icon_path))[1]
                    new_path = xbmcgui.Dialog().browse(3,
                                                       _(167) % item_shortname,
                                                       "files")
                    if bool(new_path):
                        src = os.path.normpath(
                            os.path.join(item_dirname, item_shortname))
                        dst = os.path.normpath(
                            os.path.join(new_path, item_shortname))
                        if xbmcgui.Dialog().yesno(_(164), _(166), src, dst):
                            DIALOG_PROGRESS.create(_(177),
                                                   _(178) + src,
                                                   _(179) + dst, _(110))
                            try:
                                shutil2.copy(src + ".xml",
                                             dst + ".xml",
                                             reportcopy=copy_func,
                                             overwrite=True)
                                self.fileMgr.deleteItem(src + ".xml")
                                if os.path.exists(src + icon_ext):
                                    shutil2.copy(src + icon_ext,
                                                 dst + icon_ext,
                                                 reportcopy=copy_func,
                                                 overwrite=True)
                                    self.fileMgr.deleteItem(src + icon_ext)
                            except:
                                xbmcgui.Dialog().ok(_(169), _(172), _(173))
                                print_exc()
                            self.updateDataAndList()
                            DIALOG_PROGRESS.close()
                else:
                    new_path = xbmcgui.Dialog().browse(3,
                                                       _(168) % item_basename,
                                                       "files")
                    if bool(new_path):
                        src = os.path.normpath(item_path)
                        dst = os.path.normpath(
                            os.path.join(new_path, item_basename))
                        if xbmcgui.Dialog().yesno(_(164), _(166), src, dst):
                            DIALOG_PROGRESS.create(_(177),
                                                   _(178) + src,
                                                   _(179) + dst, _(110))
                            try:
                                if os.path.isdir(src):
                                    if not os.path.isdir(os.path.dirname(dst)):
                                        os.makedirs(os.path.dirname(dst))
                                    shutil2.copytree(src,
                                                     dst,
                                                     reportcopy=copy_func,
                                                     overwrite=True)
                                else:
                                    shutil2.copy(src,
                                                 dst,
                                                 reportcopy=copy_func,
                                                 overwrite=True)
                                self.fileMgr.deleteItem(src)
                            except:
                                xbmcgui.Dialog().ok(_(169), _(172), _(173))
                                print_exc()
                            self.updateDataAndList()
                            DIALOG_PROGRESS.close()

            elif selected == 1005:
                # calcule de l'element
                src = os.path.normpath(item_path)
                DIALOG_PROGRESS.create(_(5), _(186), src)
                size = get_infos_path(src,
                                      get_size=True,
                                      report_progress=DIALOG_PROGRESS)[0]
                DIALOG_PROGRESS.close()
                self.getListItem(self.index).setProperty("size", size)
            elif selected == 1006:
                self._switch_media()
            else:
                pass
        except:
            print_exc()
예제 #13
0
def copy_dir( dirname, destination, overwrite=True ):
    if not overwrite and os.path.isdir( destination ):
        shutil2.rmtree( destination )
    shutil2.copytree( dirname, destination, overwrite=overwrite )
예제 #14
0
    def _show_context_menu( self ):
        self.index = self.getCurrentListPosition()

        try:
            # On va ici afficher un menu des options du gestionnaire de fichiers
            item_path     = self.currentItemList[ self.index-self.pardir_not_hidden ].local_path # On extrait le chemin de l'item
            item_basename = os.path.basename( item_path )

            if ( ( self.getListItem( self.index ).getProperty( "Running" ) == "true" ) or self.curListType == TYPE_ROOT or self.curListType == TYPE_PLUGIN or self.curListType == TYPE_SCRAPER ):
                # Options list for skin or add-ons currently in use
                buttons = { 1003: _( 161 ), 1005: _( 185 ), 1006: _( 1002 ) }
            elif ( self.curListType == TYPE_SCRIPT ) or ( self.curListType in self.pluginDisplayList ): 
                # Options list for plugins, scripts and scrapers
                buttons = { 1000: _( 160 ), 1001: _( 157 ), 1002: _( 156 ), 1003: _( 161 ), 1004: _( 162 ), 1005: _( 185 ), 1006: _( 1002 ) }
            else:
                # Options list for skins et scrapers
                buttons = { 1001: _( 157 ), 1002: _( 156 ), 1003: _( 161 ), 1004: _( 162 ), 1005: _( 185 ), 1006: _( 1002 ) }

            if os.path.exists( os.path.join( item_path, "description.xml" ) ):
                buttons.update( { 999: _( 1001 ) } )

            from DialogContextMenu import show_context_menu
            selected = show_context_menu( buttons, self.get_view_mode() )
            del show_context_menu

            if selected == 999:
                import infos
                infos.show_info( item_path )
                del infos

            elif selected == 1000: # Executer/Lancer
                if ( self.curListType in self.pluginDisplayList ):
                    # Cas d'un sous-plugin (video, musique ...)
                    # window id's : http://xbmc.org/wiki/?title=Window_IDs
                    if ( self.curListType == TYPE_PLUGIN_VIDEO ):
                        command = "XBMC.ActivateWindow(10025,plugin://video/%s/)" % ( item_basename, )
                    elif ( self.curListType == TYPE_PLUGIN_MUSIC ):
                        command = "XBMC.ActivateWindow(10502,plugin://music/%s/)" % ( item_basename, )
                    elif ( self.curListType == TYPE_PLUGIN_PROGRAMS ):
                        command = "XBMC.ActivateWindow(10001,plugin://programs/%s/)" % ( item_basename, )
                    elif ( self.curListType == TYPE_PLUGIN_PICTURES ):
                        command = "XBMC.ActivateWindow(10002,plugin://pictures/%s/)" % ( item_basename, )
                    #TODO: case of Weather plugin 
                elif ( self.curListType == TYPE_SCRIPT ):
                    command = "XBMC.RunScript(%s)" % ( os.path.join( item_path, "default.py" ), )

                #on ferme le script en court pour pas generer des conflits
                self._close_dialog()
                self._close_script()
                #maintenant qu'il y a plus de conflit possible, on execute la command
                xbmc.executebuiltin( command )

            elif selected == 1001: # Renommer
                # Renommer l'element
                item_dirname  = os.path.dirname( item_path )

                if ( self.curListType in [ TYPE_SCRAPER_MUSIC, TYPE_SCRAPER_VIDEO]):
                    icon_path     = self.currentItemList[ self.index-self.pardir_not_hidden ].thumb # On extrait le chemin de l'icone
                    icon_basename = os.path.basename( icon_path )
                    default_basename = os.path.splitext( item_basename )[ 0 ]
                    keyboard = xbmc.Keyboard( default_basename, _( 154 ) )
                    keyboard.doModal()
                    if ( keyboard.isConfirmed() ):
                        inputText = keyboard.getText()
                        # ne renomme pas l'item si le nouveau nom est le meme que le default
                        if default_basename != inputText:
                            self.fileMgr.renameItem( item_dirname, item_basename, inputText + '.xml' )
                            if icon_path  != get_thumb( self.curListType ):
                                self.fileMgr.renameItem( item_dirname, icon_basename, icon_basename.replace( os.path.splitext(icon_basename)[0], inputText) )
                            xbmcgui.Dialog().ok( _( 155 ), inputText )
                            self.updateDataAndList()
                else:
                    keyboard = xbmc.Keyboard( item_basename, _( 154 ) )
                    keyboard.doModal()
                    if ( keyboard.isConfirmed() ):
                        inputText = keyboard.getText()
                        # ne renomme pas l'item si le nouveau nom est le meme que le default
                        if item_basename != inputText:
                            self.fileMgr.renameItem( item_dirname, item_basename, inputText )
                            xbmcgui.Dialog().ok( _( 155 ), inputText )
                            self.updateDataAndList()

            elif selected == 1002:
                # Supprimer l'element
                if ( self.curListType in [ TYPE_SCRAPER_MUSIC, TYPE_SCRAPER_VIDEO]):
                    icon_path      = self.currentItemList[ self.index-self.pardir_not_hidden ].thumb # On extrait le chemin de l'icone
                    item_shortname = os.path.splitext(item_basename)[0] # Sans extension
                    if xbmcgui.Dialog().yesno( _( 158 )%item_shortname, _( 159 )%item_shortname ):
                        self.fileMgr.deleteItem( item_path )
                        if icon_path  != get_thumb( self.curListType ):
                            self.fileMgr.deleteItem( icon_path )
                        self.updateDataAndList()
                else:
                    if xbmcgui.Dialog().yesno( _( 158 )%item_basename, _( 159 )%item_basename ):
                        self.fileMgr.deleteItem( item_path )
                        self.updateDataAndList()

            elif selected == 1003:
                # copier l'element
                if ( self.curListType in [ TYPE_SCRAPER_MUSIC, TYPE_SCRAPER_VIDEO]):
                    #TODO : A optimiser, on doit pouvoir faire mieux
                    item_dirname   = os.path.dirname( item_path )
                    item_shortname = os.path.splitext(item_basename)[0] # Sans extension
                    icon_path      = self.currentItemList[ self.index-self.pardir_not_hidden ].thumb # On extrait le chemin de l'icone
                    icon_ext       = os.path.splitext(os.path.basename( icon_path ))[1]
                    new_path       = xbmcgui.Dialog().browse( 3, _( 167 ) % item_shortname, "files" )
                    if bool( new_path ):
                        src = os.path.normpath( os.path.join( item_dirname, item_shortname ) )
                        dst = os.path.normpath( os.path.join( new_path, item_shortname ) )
                        if xbmcgui.Dialog().yesno( _( 163 ), _( 165 ), src, dst ):
                            DIALOG_PROGRESS.create( _( 176 ), _( 178 ) + src, _( 179 ) + dst, _( 110 ) )
                            try:
                                shutil2.copy( src + ".xml", dst + ".xml", reportcopy=copy_func, overwrite=True )
                                if os.path.exists( src + icon_ext ):
                                    shutil2.copy( src + icon_ext, dst + icon_ext, reportcopy=copy_func, overwrite=True )
                            except:
                                xbmcgui.Dialog().ok( _( 169 ), _( 170 ), _( 171 ) )
                                print_exc()
                            #self.updateDataAndList()
                            DIALOG_PROGRESS.close()
                else:
                    new_path = xbmcgui.Dialog().browse( 3, _( 167 ) % item_basename, "files" )
                    if bool( new_path ):
                        src = os.path.normpath( item_path )
                        dst = os.path.normpath( os.path.join( new_path, item_basename ) )
                        if xbmcgui.Dialog().yesno( _( 163 ), _( 165 ), src, dst ):
                            DIALOG_PROGRESS.create( _( 176 ), _( 178 ) + src, _( 179 ) + dst, _( 110 ) )
                            try:
                                if os.path.isdir( src ):
                                    if not os.path.isdir( os.path.dirname( dst ) ):
                                        os.makedirs( os.path.dirname( dst ) )
                                    shutil2.copytree( src, dst, reportcopy=copy_func, overwrite=True )
                                else:
                                    shutil2.copy( src, dst, reportcopy=copy_func, overwrite=True )
                            except:
                                xbmcgui.Dialog().ok( _( 169 ), _( 170 ), _( 171 ) )
                                print_exc()
                            #self.updateDataAndList()
                            DIALOG_PROGRESS.close()

            elif selected == 1004:
                # deplacer l'element
                if ( self.curListType in [ TYPE_SCRAPER_MUSIC, TYPE_SCRAPER_VIDEO]):
                    #TODO : A optimiser, on doit pouvoir faire mieux
                    item_dirname   = os.path.dirname( item_path )
                    item_shortname = os.path.splitext(item_basename)[0] # Sans extension
                    icon_path      = self.currentItemList[ self.index-self.pardir_not_hidden ].thumb # On extrait le chemin de l'icone
                    icon_ext       = os.path.splitext(os.path.basename( icon_path ))[1]
                    new_path       = xbmcgui.Dialog().browse( 3, _( 167 ) % item_shortname, "files" )
                    if bool( new_path ):
                        src = os.path.normpath( os.path.join( item_dirname, item_shortname ) )
                        dst = os.path.normpath( os.path.join( new_path, item_shortname ) )
                        if xbmcgui.Dialog().yesno( _( 164 ), _( 166 ), src, dst ):
                            DIALOG_PROGRESS.create( _( 177 ), _( 178 ) + src, _( 179 ) + dst, _( 110 ) )
                            try:
                                shutil2.copy( src + ".xml", dst + ".xml", reportcopy=copy_func, overwrite=True )
                                self.fileMgr.deleteItem( src + ".xml" )
                                if os.path.exists( src + icon_ext ):
                                    shutil2.copy( src + icon_ext, dst + icon_ext, reportcopy=copy_func, overwrite=True )
                                    self.fileMgr.deleteItem( src + icon_ext )
                            except:
                                xbmcgui.Dialog().ok( _( 169 ), _( 172 ), _( 173 ) )
                                print_exc()
                            self.updateDataAndList()
                            DIALOG_PROGRESS.close()
                else:
                    new_path = xbmcgui.Dialog().browse( 3, _( 168 ) % item_basename, "files" )
                    if bool( new_path ):
                        src = os.path.normpath( item_path )
                        dst = os.path.normpath( os.path.join( new_path, item_basename ) )
                        if xbmcgui.Dialog().yesno( _( 164 ), _( 166 ), src, dst ):
                            DIALOG_PROGRESS.create( _( 177 ), _( 178 ) + src, _( 179 ) + dst, _( 110 ) )
                            try:
                                if os.path.isdir( src ):
                                    if not os.path.isdir( os.path.dirname( dst ) ):
                                        os.makedirs( os.path.dirname( dst ) )
                                    shutil2.copytree( src, dst, reportcopy=copy_func, overwrite=True )
                                else:
                                    shutil2.copy( src, dst, reportcopy=copy_func, overwrite=True )
                                self.fileMgr.deleteItem( src )
                            except:
                                xbmcgui.Dialog().ok( _( 169 ), _( 172 ), _( 173 ) )
                                print_exc()
                            self.updateDataAndList()
                            DIALOG_PROGRESS.close()

            elif selected == 1005:
                # calcule de l'element
                src = os.path.normpath( item_path )
                DIALOG_PROGRESS.create( _( 5 ), _( 186 ), src )
                size = get_infos_path( src, get_size=True, report_progress=DIALOG_PROGRESS )[ 0 ]
                DIALOG_PROGRESS.close()
                self.getListItem( self.index ).setProperty( "size", size )
            elif selected == 1006:
                self._switch_media()
            else:
                pass
        except:
            print_exc()
예제 #15
0
def copy_dir(dirname, destination, overwrite=True):
    if not overwrite and os.path.isdir(destination):
        shutil2.rmtree(destination)
    shutil2.copytree(dirname, destination, overwrite=overwrite)
    def copyStart(self):

        if self.twoFoldersChosen() != True:
            return

        print("Begin Copy Process")

        #create folder arrays
        self.initializeFolders()

        # Populate array with all the paths in selected source directory
        src_files = os.listdir(src)

        # Initialize variables for progress tracking
        i = 0
        e = len(src_files)

        # Start for loop with every path in array
        for file_name in src_files:

            #used to move though alphabet
            j = 0

            myFolder = ""

            while j < 26:
                if file_name[0] == alphabet[j]:
                    print(file_name + " belongs in the " + folderName[j] +
                          " folder")
                    myFolder = folderName[j]
                j += 1

            print(myFolder)

            # The full path is the concatination of the file name and the source path
            file_name_src = os.path.join(src, file_name)

            # Print the full path of source
            print("Copy from: " + file_name_src)

            if myFolder != "":
                file_name_client = os.path.join(des, myFolder)
                file_name_des = os.path.join(file_name_client, file_name)

            else:
                # The full path is the concatination of the file name and the source path
                file_name_client = des
                file_name_des = os.path.join(file_name_client, file_name)

            # Print the full path of destination
            print("Copy to: " + file_name_des)

            if os.path.exists(file_name_des) != True:

                # If the path is a file
                if (os.path.isfile(file_name_src)):

                    if os.path.exists(file_name_client) != True:

                        os.makedirs(file_name_client)

                    # Copy the file by itself
                    print("\tCopying...\n")
                    shutil2.copy2(file_name_src, file_name_des)

                # If the path is a directory
                elif (os.path.isdir(file_name_src)):

                    # Copy the full tree
                    print("\tCopying...\n")
                    shutil2.copytree(file_name_src,
                                     file_name_des,
                                     isTagInstalled=checkTag)

                # Add 1 to progress
                i += 1

                # Calculate and Report progress to user
                percentComplete = str("{:10.2f}".format(i / e * 100) + "%" +
                                      " Complete - File Copied \n")
                print(percentComplete)

            else:

                # Add 1 to progress
                i += 1

                percentComplete = str("{:10.2f}".format(i / e * 100) + "%" +
                                      " Complete - File Already Exists \n")
                print(percentComplete)

        print("Copy Process Complete")
    def copyStart(self):

        # To stop monitor once process completes
        global stopMonitor

        # used to store and report copiedFiled
        global copiedFiles

        global allFiles

        # Used to report why file copy may have failed
        failCode = 0

        # Don't start if two folders havent been chosed
        if self.twoFoldersChosen() != True:
            return

        # Let used know process has begun
        print("\nBegin Copy Process...\n")

        # Begin monitoring files in source folder
        self.startMonitoring()

        stopMonitor = False

        while monitoring != True:
            self.progressReport(
                "Waiting for file monitor to start" + "(" +
                str(monitorStatus) + ")", .5)

        print(bcolors.BLINK + "\n\nFILE MONITOR STARTED!\n" + bcolors.END)

        #create folder arrays
        self.initializeFolders()

        # Initialize variables for progress tracking
        i = 0
        e = len(allFiles)

        #Get first file
        #file_name = self.getFile(availableFiles)

        theFile = self.getFile2("Available")

        file_name = theFile[1]

        print("Fetching from queue...\n")

        print("Got file " + bcolors.BOLD + str(file_name) + bcolors.END +
              " from queue:\n")

        # Start while loop until you can't receive any more files.
        while file_name != "":

            myFolder = self.getClientFolder(file_name)

            print("\t" + bcolors.BOLD + file_name + bcolors.END +
                  " belongs in the " + bcolors.BOLD + myFolder + bcolors.END +
                  " folder")

            # The full path is the concatination of the file name and the source path
            file_name_src = os.path.join(src, file_name)

            # Set the destination folder depending on file's first initial
            if myFolder != "":

                file_name_client = os.path.join(des, myFolder)
                file_name_des = os.path.join(file_name_client, file_name)

            else:

                # The full path is the concatination of the file name and the source path
                file_name_client = des
                file_name_des = os.path.join(file_name_client, file_name)

            # Print the full path of source
            print("\tCopy from: " + file_name_src)

            # Print the full path of destination
            print("\tCopy to: " + file_name_des)

            # Set and initialize boolean that will keep track of copying
            copiedSuccesfully = False

            # Begin Copy Procedure
            if os.path.exists(file_name_des) != True:

                # If the path is a file
                if (os.path.isfile(file_name_src)):

                    if os.path.exists(file_name_client) != True:

                        os.makedirs(file_name_client)

                    # Copy the file by itself
                    print("\tCopying...\n")

                    try:

                        shutil2.copy2(file_name_src, file_name_des)
                        copiedSuccesfully = True

                    except:

                        failCode = 2

                        copiedSuccesfully = False

                    #if copiedAvailableBytes == True:

                    # Verify all bytes have been written
                    #TODO: Write code to handle verification of a single file

                # If the path is a directory
                elif (os.path.isdir(file_name_src)):

                    currentFolderSize = self.get_size(file_name_src)

                    if currentFolderSize == theFile[2]:

                        dirAvail = self.isDirInUse(start_path=file_name_src,
                                                   printResults=True,
                                                   stream=False,
                                                   pollTime=10)

                        if dirAvail != True:
                            # Copy the full tree
                            print("\r\tCopying...")

                            try:

                                shutil2.copytree(file_name_src,
                                                 file_name_des,
                                                 isTagInstalled=checkTag)
                                copiedSuccesfully = True

                            except:

                                failCode = 0

                                copiedSuccesfully = False

                        else:

                            failCode = 1

                            copiedSuccesfully = False

                    else:

                        failCode = 2

                        copiedSuccesfully = False

                # Add 1 to progress
                i += 1

                #Reporting

                if copiedSuccesfully == True:

                    # Verify file size is the same
                    filePass = self.verifyFiles(file_name_src, file_name_des)

                    if filePass == True:

                        # Calculate and Report progress to user
                        percentComplete = str("{:10.2f}".format(i / e * 100) +
                                              "%" +
                                              " Complete - File Copied \n")
                        theFile = (theFile[0], theFile[1], theFile[2],
                                   "Copied")
                        print(bcolors.GREEN + percentComplete + bcolors.END)

                    else:

                        # Add file to modified array
                        self.modifiedInQueue([file_name])

                        # Calculate and Report progress to user
                        percentComplete = str(
                            "{:10.2f}".format(i / e * 100) + "%" +
                            " Complete - File Verification Failed \n")
                        theFile = (theFile[0], theFile[1], theFile[2],
                                   "Failed Verification")
                        print(bcolors.YELLOW + percentComplete + bcolors.END)

                else:

                    #TODO: Add if statements for Failcode variables

                    # Calculate and Report progress to user

                    if failCode == 0:

                        percentComplete = str(
                            "{:10.2f}".format(i / e * 100) + "%" +
                            " Complete - File Copying Failed \n")
                        theFile = (theFile[0], theFile[1], theFile[2],
                                   "Failed")
                        print(bcolors.RED + percentComplete + bcolors.END)

                    elif failCode == 1:

                        percentComplete = str(
                            "{:10.2f}".format(i / e * 100) + "%" +
                            " Complete - File In Use, Will Try Again Later \n")
                        theFile = (theFile[0], theFile[1], theFile[2], "Busy")
                        print(bcolors.YELLOW + percentComplete + bcolors.END)

                    elif failCode == 2:

                        percentComplete = str(
                            "{:10.2f}".format(i / e * 100) + "%" +
                            " Complete - File Modified During Copy Process \n")
                        theFile = (theFile[0], theFile[1], theFile[2],
                                   "Modified")
                        print(bcolors.YELLOW + percentComplete + bcolors.END)

            else:

                # Add 1 to progress
                i += 1

                percentComplete = str("{:10.2f}".format(i / e * 100) + "%" +
                                      " Complete - File Already Exists \n")
                theFile = (theFile[0], theFile[1], theFile[2], "Not Copied")
                print(bcolors.YELLOW + percentComplete + bcolors.END)

            fileIndex = theFile[0]

            allFiles[fileIndex] = theFile

            theFile = self.getFile2("Available")

            if theFile != "":

                file_name = theFile[1]

                print("Got file " + str(file_name) + " from queue:\n")

            else:

                while queueBusy:

                    self.progressReport("Waiting for file", .5)

                theFile = self.getFile2("Available")

                if theFile != "":

                    file_name = theFile[1]

                    print("Got file " + str(file_name) + " from queue:\n")

                else:

                    busyCount = self.countQueue("Busy")
                    modifiedCount = self.countQueue("Modified")
                    failedCount = self.countQueue("Failed")
                    copiedCount = self.countQueue("Copied")

                    answer = input(
                        "There are no files available to copy,\nWould you like to check if Busy files are available now?"
                    )

                    if answer == "Y":

                        self.checkQueue()

                        theFile = self.getFile2("Available")

                        if theFile != "":

                            file_name = theFile[1]

                            print("Got file " + str(file_name) +
                                  " from queue:\n")

                        else:

                            file_name = ""

                    else:

                        file_name = ""

        stopMonitor = True

        time.sleep(5)

        print("Copy Process Complete\n")

        self.printReport()