Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, urllib, os
- SRLDir = '/home/michael/tmpsrl/'
- PlugDir = '/home/michael/tmpplug/'
- SRLUrl = 'http://www.villavu.com/repositories/srl-opendev/'
- class TFile(object):
- def __init__(self, path, name):
- self.path = path
- self.name = name
- class TSVNFile(object):
- def __init__(self, local, remote):
- self.local = local
- self.remote = remote
- class TMatch(object):
- def __init__(self, start, finish):
- self.start = start
- self.finish = finish
- class TFilter(object):
- def __init__(self, exp, dire, fil, local, remote):
- self.exp = exp
- self.dir = dire
- self.fil = fil
- self.local = local
- self.remote = remote
- class TSVN(object):
- def __init__(self, skip, base, files, fil):
- self.skip = skip
- self.base = base
- self.files = files
- self.fil = fil
- def returnPage(svn, dire):
- url = svn.base.remote.path + dire.remote.path
- f = urllib.urlopen(url)
- return f.read()
- def between(inp, st, en):
- s = inp.find(st) + len(st)
- e = inp.find(en, s)
- if (s == len(st) - 1) or (e == -1):
- return ''
- else:
- return inp[s:e]
- def rawCollectSVN(svn, curdir):
- lsvn = svn
- inp = returnPage(svn, curdir)
- spl = inp.split(svn.fil.exp)
- sk = False
- for cur in spl:
- for skip in svn.skip:
- sk = cur.find(skip) == -1
- if sk:
- break
- if sk:
- continue
- tmploc = between(cur, svn.fil.local.start, svn.fil.local.finish)
- tmprem = between(cur, svn.fil.remote.start, svn.fil.remote.finish)
- if (tmploc == '') or (tmprem == ''):
- continue
- if cur.find(svn.fil.dir) != -1:
- newdir = TSVNFile(TFile(curdir.local.path + tmploc + '/', ''), TFile(curdir.remote.path + tmprem, ''))
- print('Discovered new directory "' + tmploc + '"')
- lsvn = rawCollectSVN(svn, newdir)
- print('Finished collecting from "' + tmploc + '"')
- else:
- if cur.find(svn.fil.fil) != -1:
- lsvn.files.append(TSVNFile(TFile(curdir.local.path, tmploc), TFile(curdir.remote.path, tmprem)))
- return lsvn
- def collectSVN(svn):
- print('Now starting to collect the svn')
- lsvn = rawCollectSVN(svn, TSVNFile(TFile('', ''), TFile('', '')))
- return lsvn
- def ensure_dir(f):
- d = os.path.dirname(f)
- if not os.path.exists(d):
- os.makedirs(d)
- def downloadSVN(svn):
- print('Now starting to download the svn')
- c = 0
- for cur in svn.files:
- c += 1
- if c % 10 == 0:
- print('Downloading file ' + str(c) + ' of ' + str(len(svn.files)))
- ensure_dir(svn.base.local.path + cur.local.path)
- f = urllib.urlopen(svn.base.remote.path + cur.remote.path + cur.remote.name)
- s = f.read()
- f.close()
- f = open(svn.base.local.path + cur.local.path + cur.local.name, 'w')
- f.write(s)
- f.close()
- print('Finished downloading the svn')
- def returnSRLSVN():
- return TSVN((), TSVNFile(TFile(SRLDir, ''), TFile(SRLUrl, '')), [], TFilter('<', 'dir', 'file', TMatch('name="', '"'), TMatch('href="', '"')))
- def movePlugins(svn):
- ensure_dir(PlugDir)
- for cur in svn.files:
- if cur.local.name.endswith('.dll'):
- print('Found plugin "' + cur.local.name + '"')
- f = open(svn.base.local.path + cur.local.path + cur.local.name, 'r')
- s = f.read()
- f.close()
- f = open(PlugDir + cur.local.name, 'w')
- f.write(s)
- f.close()
- svn = collectSVN(returnSRLSVN())
- downloadSVN(svn)
- movePlugins(svn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement