Advertisement
mixster

mixster

Apr 10th, 2010
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.25 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.     s = f.read()
  40.     f.close()
  41.     return s
  42.  
  43. def between(inp, st, en):
  44.     s = inp.find(st) + len(st)
  45.     e = inp.find(en, s)
  46.     if (s == len(st) - 1) or (e == -1):
  47.         return ''
  48.     else:
  49.         return inp[s:e]
  50.  
  51. def rawCollectSVN(svn, curdir):
  52.     lsvn = svn
  53.     inp = returnPage(svn, curdir)
  54.     spl = inp.split(svn.fil.exp)
  55.     sk = False
  56.  
  57.     for cur in spl:
  58.         for skip in svn.skip:
  59.             sk = cur.find(skip) == -1
  60.             if sk:
  61.                 break
  62.         if sk:
  63.             continue
  64.  
  65.  
  66.         tmploc = between(cur, svn.fil.local.start, svn.fil.local.finish)
  67.         tmprem = between(cur, svn.fil.remote.start, svn.fil.remote.finish)
  68.  
  69.         if (tmploc == '') or (tmprem == ''):
  70.             continue
  71.  
  72.         if cur.find(svn.fil.dir) != -1:
  73.             newdir = TSVNFile(TFile(curdir.local.path + tmploc + '/', ''), TFile(curdir.remote.path + tmprem, ''))
  74.             print('Discovered new directory "' + tmploc + '"')
  75.             lsvn = rawCollectSVN(svn, newdir)
  76.             print('Finished collecting from "' + tmploc + '"')
  77.         else:
  78.             if cur.find(svn.fil.fil) != -1:
  79.                 lsvn.files.append(TSVNFile(TFile(curdir.local.path, tmploc), TFile(curdir.remote.path, tmprem)))
  80.     return lsvn
  81.  
  82. def collectSVN(svn):
  83.     print('Now starting to collect the svn')
  84.     lsvn = rawCollectSVN(svn, TSVNFile(TFile('', ''), TFile('', '')))
  85.     return lsvn
  86.  
  87. def ensure_dir(f):
  88.     d = os.path.dirname(f)
  89.     if not os.path.exists(d):
  90.         os.makedirs(d)
  91.  
  92. def downloadSVN(svn):
  93.     print('Now starting to download the svn')
  94.  
  95.     c = 0
  96.     for cur in svn.files:
  97.         c += 1
  98.         if c % 10 == 0:
  99.             print('Downloading file ' + str(c) + ' of ' + str(len(svn.files)))
  100.  
  101.         ensure_dir(svn.base.local.path + cur.local.path)
  102.         f = urllib.urlopen(svn.base.remote.path + cur.remote.path + cur.remote.name)
  103.         s = f.read()
  104.         f.close()
  105.         f = open(svn.base.local.path + cur.local.path + cur.local.name, 'w')
  106.         f.write(s)
  107.         f.close()
  108.  
  109.     print('Finished downloading the svn')
  110.  
  111. def returnSRLSVN():
  112.     return TSVN((), TSVNFile(TFile(SRLDir, ''), TFile(SRLUrl, '')), [], TFilter('<', 'dir', 'file', TMatch('name="', '"'), TMatch('href="', '"')))
  113.  
  114. def movePlugins(svn):
  115.     ensure_dir(PlugDir)
  116.     for cur in svn.files:
  117.         if cur.local.name.endswith('.dll'):
  118.             print('Found plugin "' + cur.local.name + '"')
  119.             f = open(svn.base.local.path + cur.local.path + cur.local.name, 'r')
  120.             s = f.read()
  121.             f.close()
  122.             f = open(PlugDir + cur.local.name, 'w')
  123.             f.write(s)
  124.             f.close()
  125.  
  126. svn = collectSVN(returnSRLSVN())
  127. downloadSVN(svn)
  128. movePlugins(svn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement