Advertisement
simontfs

Untitled

May 17th, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.86 KB | None | 0 0
  1. import xbmcgui                               # include xbmc gui module for script to use
  2. import xbmc                                  # include xbmc module built in commands for script to use
  3. import os                                    # include os module for file modification
  4. import shutil                                # include shutil module for removal of files and folders
  5.  
  6. TARGETFOLDER = xbmc.translatePath(           # defines TARGETFOLDER with X-platform directory structure
  7.     'special://home/userdata/addon_data/01'  # the actual directory location of folder 01
  8.     )                                        # Close the definition of TARGETFOLDER
  9. YESNOWINDOW = xbmcgui.Dialog().yesno(        # Define YESWINDOW as kodi builtin window called Dialog().yesno
  10.     "This Will Delete a folder",             # Heading of builtin window
  11.     "Click yes to delete",                   # body Text line 1
  12.     "Click No to exit")                      # body text line 2
  13.  
  14.  
  15. if YESNOWINDOW:                              # Dialog window is activated with yesbutton
  16.     _MSG = None                              # defines _MSG as blank, do not create a message. _MSG is what will links Notifications later on
  17.     if os.path.exists(TARGETFOLDER):         # if TARGETFOLDER exists at the defined location from above (line 6)
  18.         try:                                 # first attempt to....
  19.             shutil.rmtree(TARGETFOLDER, ignore_errors=False)#remove TARGETFOLDER
  20.             xbmc.executebuiltin("Notification(Folder has been deleted, All done,()")# if folder is removed, show notification (if yes button and folder is present)
  21.             xbmc.executebuiltin("ActivateWindow(10000,return)")# then return to homescreen
  22.         except OSError as rmerr:             # if removal fails because file is not accessable
  23.             _MSG = ("Error with delete dir: {}".format(rmerr)) # this will be the message output defined as rmerr
  24.         except Exception as err:             # if removal fails because kodi doesnt understand any or some of the code
  25.             _MSG = ("Error with XBMC call: {}".format(err))# this will be the error message defined as err
  26.     else:                                    # if try is not selected and neither of the excepts line 22 and 24 are triggered
  27.         _MSG = ("Folder {}, does not appear to be a directory"# this is the notification _MSG inside curly brackets will be printed
  28.                 .format(TARGETFOLDER))       # TARGETFOLDER path as defined by .format
  29.     if _MSG:                                 # if OSError-rmerr- or EXCEPTION-err- is activated due to a problem, ......read below
  30.         xbmc.executebuiltin("Notification({},()".format(_MSG)) # pop up the notification window, inside curly brackets text will be from _MSG either OSError or Exception
  31.         xbmc.executebuiltin("ActivateWindow(10000,return)")    # then activate 10000,return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement