Advertisement
mixster

mixster

Apr 10th, 2010
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.23 KB | None | 0 0
  1. import sys, urllib, os
  2. SRLDir = '/home/michael/tmpsrl/'
  3. PlugDir = '/home/michael/tmpplug/'
  4. SRLUrl = 'http://www.villavu.com/repositories/srl-opendev/'
  5.  
  6. class TFile(object):
  7.     def __init__(self, path, name):
  8.         self.path = path
  9.         self.name = name
  10.  
  11. class TSVNFile(object):
  12.     def __init__(self, local, remote):
  13.         self.local = local
  14.         self.remote = remote
  15.  
  16. class TMatch(object):
  17.     def __init__(self, start, finish):
  18.         self.start = start
  19.         self.finish = finish
  20.  
  21. class TFilter(object):
  22.     def __init__(self, exp, dire, fil, local, remote):
  23.         self.exp = exp
  24.         self.dir = dire
  25.         self.fil = fil
  26.         self.local = local
  27.         self.remote = remote
  28.  
  29. class TSVN(object):
  30.     def __init__(self, skip, base, files, fil):
  31.         self.skip = skip
  32.         self.base = base
  33.         self.files = files
  34.         self.fil = fil
  35.  
  36. def returnPage(svn, dire):
  37.     url = svn.base.remote.path + dire.remote.path
  38.     f = urllib.urlopen(url)
  39.     return f.read()
  40.  
  41. def between(inp, st, en):
  42.     s = inp.find(st) + len(st)
  43.     e = inp.find(en, s)
  44.     if (s == len(st) - 1) or (e == -1):
  45.         return ''
  46.     else:
  47.         return inp[s:e]
  48.  
  49. def rawCollectSVN(svn, curdir):
  50.     lsvn = svn
  51.     inp = returnPage(svn, curdir)
  52.     spl = inp.split(svn.fil.exp)
  53.     sk = False
  54.  
  55.     for cur in spl:
  56.         for skip in svn.skip:
  57.             sk = cur.find(skip) == -1
  58.             if sk:
  59.                 break
  60.         if sk:
  61.             continue
  62.  
  63.  
  64.         tmploc = between(cur, svn.fil.local.start, svn.fil.local.finish)
  65.         tmprem = between(cur, svn.fil.remote.start, svn.fil.remote.finish)
  66.  
  67.         if (tmploc == '') or (tmprem == ''):
  68.             continue
  69.  
  70.         if cur.find(svn.fil.dir) != -1:
  71.             newdir = TSVNFile(TFile(curdir.local.path + tmploc + '/', ''), TFile(curdir.remote.path + tmprem, ''))
  72.             print('Discovered new directory "' + tmploc + '"')
  73.             lsvn = rawCollectSVN(svn, newdir)
  74.             print('Finished collecting from "' + tmploc + '"')
  75.         else:
  76.             if cur.find(svn.fil.fil) != -1:
  77.                 lsvn.files.append(TSVNFile(TFile(curdir.local.path, tmploc), TFile(curdir.remote.path, tmprem)))
  78.     return lsvn
  79.  
  80. def collectSVN(svn):
  81.     print('Now starting to collect the svn')
  82.     lsvn = rawCollectSVN(svn, TSVNFile(TFile('', ''), TFile('', '')))
  83.     return lsvn
  84.  
  85. def ensure_dir(f):
  86.     d = os.path.dirname(f)
  87.     if not os.path.exists(d):
  88.         os.makedirs(d)
  89.  
  90. def downloadSVN(svn):
  91.     print('Now starting to download the svn')
  92.  
  93.     c = 0
  94.     for cur in svn.files:
  95.         c += 1
  96.         if c % 10 == 0:
  97.             print('Downloading file ' + str(c) + ' of ' + str(len(svn.files)))
  98.  
  99.         ensure_dir(svn.base.local.path + cur.local.path)
  100.         f = urllib.urlopen(svn.base.remote.path + cur.remote.path + cur.remote.name)
  101.         s = f.read()
  102.         f.close()
  103.         f = open(svn.base.local.path + cur.local.path + cur.local.name, 'w')
  104.         f.write(s)
  105.         f.close()
  106.  
  107.     print('Finished downloading the svn')
  108.  
  109. def returnSRLSVN():
  110.     return TSVN((), TSVNFile(TFile(SRLDir, ''), TFile(SRLUrl, '')), [], TFilter('<', 'dir', 'file', TMatch('name="', '"'), TMatch('href="', '"')))
  111.  
  112. def movePlugins(svn):
  113.     ensure_dir(PlugDir)
  114.     for cur in svn.files:
  115.         if cur.local.name.endswith('.dll'):
  116.             print('Found plugin "' + cur.local.name + '"')
  117.             f = open(svn.base.local.path + cur.local.path + cur.local.name, 'r')
  118.             s = f.read()
  119.             f.close()
  120.             f = open(PlugDir + cur.local.name, 'w')
  121.             f.write(s)
  122.             f.close()
  123.  
  124. svn = collectSVN(returnSRLSVN())
  125. downloadSVN(svn)
  126. movePlugins(svn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement