2015-11-23, 23:38
Good evening,
I'm writing a program for anyone to use. Anyone interested please feel free to use the code. Replace * with your addon. All you have to do is zip your settings(userdata/addon_data/plugin,*.*) and add them to Maintenance/* folder in Super Favourites. All works great except for the last bit where I want to delete the zip file. This is important as it checks if a zip file is present in specified folder.
I get an error
here is the code
Can anyone please shed light on the error. Thanks a million.
I'm writing a program for anyone to use. Anyone interested please feel free to use the code. Replace * with your addon. All you have to do is zip your settings(userdata/addon_data/plugin,*.*) and add them to Maintenance/* folder in Super Favourites. All works great except for the last bit where I want to delete the zip file. This is important as it checks if a zip file is present in specified folder.
I get an error
Code:
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.TypeError'>
Error Contents: coercing to Unicode: need string or buffer, bool found
Traceback (most recent call last):
File "/home/usuario/.kodi/userdata/addon_data/plugin.program.super.favourites/Super Favourites/Maintenance/*update/*update.py", line 71, in <module>
checkifthereisupdatezip() , removezip()
File "/home/usuario/.kodi/userdata/addon_data/plugin.program.super.favourites/Super Favourites/Maintenance/*update/*update.py", line 20, in removezip
shutil.rmtree(yesremove,)
File "/usr/lib/python2.7/shutil.py", line 228, in rmtree
if os.path.islink(path):
File "/usr/lib/python2.7/posixpath.py", line 142, in islink
st = os.lstat(path)
TypeError: coercing to Unicode: need string or buffer, bool found
-->End of Python script error report<--
here is the code
Code:
import os
import xbmc
import xbmcgui
import zipfile
import shutil
import time
import datetime
import smtplib
#IMPORT MODULES
updateziplocation = xbmc.translatePath('special://home/userdata/addon_data/plugin.program.super.favourites/Super Favourites/Maintenance/*update/plugin.video.*.zip')
*userdata = xbmc.translatePath('special://home/userdata/addon_data/plugin.video.*')
now = datetime.datetime.now()
runtime = now.strftime("%d-%m-%Y %H:%M")
#functions
def removezip():
updateziplocation = xbmc.translatePath('special://home/userdata/addon_data/plugin.program.super.favourites/Super Favourites/Maintenance/*update/plugin.video.*.zip')
yesremove = os.path.exists(updateziplocation)
shutil.rmtree(yesremove, ignore_errors=False)
def checkifthereisupdatezip():
now = datetime.datetime.now()
runtime = now.strftime("%d-%m-%Y %H:%M")
yeszip = os.path.exists(updateziplocation)
if yeszip:
xbmc.executebuiltin("Notification(Yes There is an Update, Over-writing previos Settings,()")
old*settings = xbmc.translatePath('special://home/userdata/addon_data/plugin.video.*')
shutil.rmtree(old*settings, ignore_errors=False)
xbmc.executebuiltin("Notification(Old * Settings Removed, Installing new Settings,()")
fh = open(updateziplocation, 'rb')
z = zipfile.ZipFile(fh)
for name in z.namelist():
z.extract(name, old*settings)
fh.close()
xbmcgui.Dialog().ok(
"Thankyou for using * Update",
"Your * settings have been updated",
"Read the news feed for information about",
"when * settings are next updated")
else:
YESNOWINDOW = xbmcgui.Dialog().yesno(
"There are no new settings at the moment",
"ONLY IF...* has stopped working",
"Would you like to send a message to Admin",
"Asking for an update?",
"No Thanks",
"Yes Please"
)
if YESNOWINDOW:
mailserver = smtplib.SMTP("smtp.mail.com",587)
mailserver.ehlo()
mailserver.starttls()
mailserver.login('somemail','somepwd')
mailserver.sendmail('somemail','somemail', ' * Update Request ' + runtime )
mailserver.close()
xbmcgui.Dialog().ok(
"Thankyou for using * Update",
"An Email has been sent to Admin",
"Requesting * settings update",
"")
else:
xbmcgui.Dialog().ok(
"Thankyou for using * Update",
"Nothing on your system has changed",
"Read the news feed for information about",
"when * settings are updated next")
checkifthereisupdatezip() , removezip()
Can anyone please shed light on the error. Thanks a million.