コード例 #1
0
def __insmod__(path, r):
  mod = open(path, "r")
  try:
    exec(mod.read())
    mod.close()
  except Exception as e:
    mod.close()
    Logger.err("Module insertion failed: " + r)
    Logger.fatal(e)
コード例 #2
0
ファイル: MTS.py プロジェクト: ChameleonLinux/SimsModder
 def get(self, data):
   id, dest, type, fname = data
   Logger.info("Downloading informations... ("+str(id)+")")
   useragent = self.scope['UserAgent']
   dest = self.scope['Directories'][dest]
   if os.path.exists(self.scope['Directories']['Cache'] + "/" + fname):
     if not "ignore_cached" in sys.argv:
       Logger.warn("Using from cache: " + fname)
       self.decompress(fname, dest, type)
     return
   url = "http://modthesims.info/download.php?t=" + id + "#actualtab1"
   req = urllib.request.Request(url, data=None, headers={"User-Agent": useragent})
   response = urllib.request.urlopen(req)
   html = b''
   chunk = True
   while chunk:
     chunk = response.read(1024)
     html += chunk
   html = BeautifulSoup(html, "html.parser")
   title = html.body.find('div', attrs={'class': "well profilepic well-small well-inline"}).find("h2").text.strip()
   author = html.body.find('div', attrs={'class': "well profilepic well-small well-inline"}).find("div", attrs={'class': "pull-left"}).text.strip().replace("\n", " ")
   try:
     author = author.split(" ", 2)[1]
   except Exception:
     author = "(unknown)"
   Logger.warn("Downloading: "+"\""+title+"\" ("+fname+") by " + author +" ("+url+")")
   files = html.body.find('div', attrs={'id': 'actualtab1'}).find('tbody').find_all('tr')
   furl = None
   try:
     for file in files:
       a = file.find("a")
       if a.text.strip() == fname:
         furl = a['href']
         break
   except Exception:
     furl = None
   if not furl:
     if not "mts_ignore_errors" in sys.argv:
       Logger.fatal("No such file.")
     else: Logger.err("No such file.")
   Logger.info("Found URL: " + furl)
   req = urllib.request.Request(furl, data=None, headers={"User-Agent": useragent})
   response = urllib.request.urlopen(req)
   o_ = open(self.scope['Directories']['Cache'] + "/" + fname, "wb")
   o_.write(response.read())
   o_.close()
   self.decompress(fname, dest, type)
コード例 #3
0
ファイル: Parser.py プロジェクト: ChameleonLinux/SimsModder
def read(fname):
  f = open(fname, "r")
  super = {}
  data = []
  try:
    for l in f.readlines():
      l = l.strip()
      if l[0] == "#":
        continue
      if l[0] == "@":
        l = l[1:].split(" ", 1)
        super[l[0].strip()] = l[1].strip()
      elif l.startswith("- "): 
        l = l[2:].strip().split(" ", 3)
        data.append(l)
  except Exception as e:
    Logger.err("Parse error.")
    Logger.fatal(e)
  return {"super": super, "data": data}