2004-11-23, 02:32
i have pretty everything worked out, but is there anyway to make os.mkdir work in xbmc?
(mpauley73 @ nov. 24 2004,16:32 Wrote:....aaaaand im done :kickass: . xbmsync is complete. this script logs into my ftp server and downloads the latest skins, scripts and stuff. any beta testers out there that want to give this a try?i will.... pm me.. or email...
-mp
**if the authors of the skins and scripts do not want me hosting and sharing them this way, please let me know.
Quote:# python xbmc script to download scripts, skins and stuff
#
# this is a basic script that will verify that you want to run it and then just run in the background
installroot = "f:\\apps\\xbmc\\"
import xbmc, xbmcgui, os
from ftplib import ftp
emulating = hasattr(xbmcgui, "emulating")
class remoteobject(object):
"""
abstract superclass. don't instantiate directly.
"""
def (self,filename,parent,delim='/'):
self.filename = filename
self.parent = parent
self.delim = delim
def getpath(self):
"""
method to determine the full path of remoteobject.
"""
currentparent = self.parent
if currentparent is none:
return self.filename
tmppath = ''
delim = self.delim
while currentparent is not none:
tmppath = delim.join([currentparent.filename,tmppath])
currentparent = currentparent.parent
return '%s%s'%(tmppath,self.filename)
class remotedir(remoteobject):
def (self,filename,parent):
remoteobject.(self,filename,parent)
self.contents = []
def retrieve(self,ftp=none,localroot=none):
remotepath = self.getpath()
l = len(remotepath)
remotepath = remotepath[1 : l]
localpath = '%s%s'%(localroot,remotepath)
ftp.retrlines('list %s'%(remotepath),self._rcb)
if not os.path.exists(localpath):
os.mkdir(localpath)
def _rcb(self,line):
"""
callback function for use with ftplib.ftp.retrlines
"""
fname = line.split()[-1]
if line.startswith('d'):
self.contents.append(remotedir(fname,self))
else:
self.contents.append(remotefile(fname,self))
class remotefile(remoteobject):
def (self,name,parent):
remoteobject.(self,name,parent)
def retrieve(self,ftp=none,localroot=none):
remotepath = self.getpath()
localpath = '%s%s'%(localroot,remotepath)
ftp.retrbinary('retr %s'%remotepath,open(localpath,'wb').write)
class ftpretriever(object):
def (self,server='ftp.your_server_name_here.com',username='here',
password='here'):
self.ftp = ftp(server,username,password)
self.container = []
def run(self,remoteroot='/',localroot='ftptmp'):
"""
method to coordinate the work required to
retrieve a directory from an ftp server.
"""
if not os.path.exists(localroot):
os.mkdir(localroot)
root = remotedir(filename=remoteroot,parent=none)
root.retrieve(self.ftp,localroot)
self.container.extend(root.contents)
while self.container:
item = self.container.pop()
item.retrieve(self.ftp,localroot)
try:
self.container.extend(item.contents)
except attributeerror:
continue
if == '':
dialog = xbmcgui.dialog()
selected = dialog.yesno("xbmsync", "are you ready to run xbmsync?")
if selected == true:
if not os.path.exists(installroot):
try:
os.mkdir(installroot)
except:
dialog.ok("error", "failed to created folder")
r = ftpretriever()
r.run(remoteroot='',localroot= installroot)
Quote: def _rcb(self,line):
"""
callback function for use with ftplib.ftp.retrlines
"""
fname = line.split()[-1]
if line.startswith('d'):
self.contents.append(remotedir(fname,self))
else:
self.contents.append(remotefile(fname,self))