Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None
  1. import sys
  2. import app
  3. import dbg
  4.  
  5. sys.path.append("lib")
  6.  
  7. def StringColorToInt(colorstring):
  8. import grp
  9.  
  10. colorstring = colorstring.strip()
  11.  
  12. if len(colorstring) != 8:
  13. raise ValueError, "input #%s is not in #AARRGGBB format" % colorstring
  14.  
  15. a, r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:6],colorstring[6:8]
  16. a, r, g, b = [int(n, 16) for n in (a, r, g, b)]
  17.  
  18. return grp.GenerateColor(floatĀ® / 255.0, float(g) / 255.0, float(b) / 255.0, float(a) / 255.0)
  19.  
  20. __builtin__.CTOA = StringColorToInt
  21.  
  22. class TraceFile:
  23. def write(self, msg):
  24. dbg.Trace(msg)
  25.  
  26. class TraceErrorFile:
  27. def write(self, msg):
  28. dbg.TraceError(msg)
  29. dbg.RegisterExceptionString(msg)
  30.  
  31. class LogBoxFile:
  32. def __init__(self):
  33. self.stderrSave = sys.stderr
  34. self.msg = ""
  35.  
  36. def __del__(self):
  37. self.restore()
  38.  
  39. def restore(self):
  40. sys.stderr = self.stderrSave
  41.  
  42. def write(self, msg):
  43. self.msg = self.msg + msg
  44.  
  45. def show(self):
  46. dbg.LogBox(self.msg,"Error")
  47.  
  48. sys.stdout = TraceFile()
  49. sys.stderr = TraceErrorFile()
  50.  
  51. #
  52. # pack file support (must move to system.py, systemrelease.pyc)
  53. #
  54.  
  55. import marshal
  56. import imp
  57. import pack
  58.  
  59. class pack_file_iterator(object):
  60. def __init__(self, packfile):
  61. self.pack_file = packfile
  62.  
  63. def next(self):
  64. tmp = self.pack_file.readline()
  65. if tmp:
  66. return tmp
  67. raise StopIteration
  68.  
  69. _chr = __builtins__.chr
  70.  
  71. class pack_file(object):
  72.  
  73. def __init__(self, filename, mode = 'rb'):
  74. assert mode in ('r', 'rb')
  75. if not pack.Exist(filename):
  76. raise IOError, 'No file or directory'
  77. self.data = pack.Get(filename)
  78. if mode == 'r':
  79. self.data=_chr(10).join(self.data.split(_chr(13)+_chr(10)))
  80.  
  81. def __iter__(self):
  82. return pack_file_iterator(self)
  83.  
  84. def read(self, len = None):
  85. if not self.data:
  86. return ''
  87. if len:
  88. tmp = self.data[:len]
  89. self.data = self.data[len:]
  90. return tmp
  91. else:
  92. tmp = self.data
  93. self.data = ''
  94. return tmp
  95.  
  96. def readline(self):
  97. return self.read(self.data.find(_chr(10))+1)
  98.  
  99. def readlines(self):
  100. return [x for x in self]
  101.  
  102. __builtins__.pack_open = pack_open = pack_file
  103.  
  104. _ModuleType = type(sys)
  105.  
  106. old_import = __import__
  107. def _process_result(code, fqname):
  108. # did get_code() return an actual module? (rather than a code object)
  109. is_module = isinstance(code, _ModuleType)
  110.  
  111. # use the returned module, or create a new one to exec code into
  112. if is_module:
  113. module = code
  114. else:
  115. module = imp.new_module(fqname)
  116.  
  117. # insert additional values into the module (before executing the code)
  118. #module.__dict__.update(values)
  119.  
  120. # the module is almost ready... make it visible
  121. sys.modules[fqname] = module
  122.  
  123. # execute the code within the module's namespace
  124. if not is_module:
  125. exec code in module.__dict__
  126.  
  127. # fetch from sys.modules instead of returning module directly.
  128. # also make module's __name__ agree with fqname, in case
  129. # the "exec code in module.__dict__" played games on us.
  130. module = sys.modules[fqname]
  131. module.__name__ = fqname
  132. return module
  133.  
  134. module_do = lambda x:None
  135.  
  136. def __pack_import(name,globals=None,locals=None,fromlist=None):
  137. if name in sys.modules:
  138. return sys.modules[name]
  139.  
  140. filename = name + '.py'
  141.  
  142. if pack.Exist(filename):
  143. dbg.Trace('importing from pack %s\\n' % name)
  144.  
  145. newmodule = _process_result(compile(pack_file(filename,'r').read(),filename,'exec'),name)
  146.  
  147. module_do(newmodule)
  148. return newmodule
  149. #return imp.load_module(name, pack_file(filename,'r'),filename,('.py','r',imp.PY_SOURCE))
  150. else:
  151. dbg.Trace('importing from lib %s\\n' % name)
  152. return old_import(name,globals,locals,fromlist)
  153.  
  154. def splitext(p):
  155. root, ext = '', ''
  156. for c in p:
  157. if c in ['/']:
  158. root, ext = root + ext + c, ''
  159. elif c == '.':
  160. if ext:
  161. root, ext = root + ext, c
  162. else:
  163. ext = c
  164. elif ext:
  165. ext = ext + c
  166. else:
  167. root = root + c
  168. return root, ext
  169.  
  170. class PythonExecutioner:
  171.  
  172. def Run(kPESelf, sFileName, kDict):
  173. if kPESelf.__IsCompiledFile__(sFileName):
  174. kCode=kPESelf.__LoadCompiledFile__(sFileName)
  175. else:
  176. kCode=kPESelf.__LoadTextFile__(sFileName)
  177.  
  178. exec(kCode, kDict)
  179.  
  180. def __IsCompiledFile__(kPESelf, sFileName):
  181.  
  182. sBase, sExt = splitext(sFileName)
  183. sExt=sExt.lower()
  184.  
  185. if sExt==".pyc" or sExt==".pyo":
  186. return 1
  187. else:
  188. return 0
  189.  
  190. def __LoadTextFile__(kPESelf, sFileName):
  191. sText=pack_open(sFileName,'r').read()
  192. return compile(sText, sFileName, "exec")
  193.  
  194. def __LoadCompiledFile__(kPESelf, sFileName):
  195. kFile=pack_open(sFileName)
  196.  
  197. if kFile.read(4)!=imp.get_magic():
  198. raise
  199.  
  200. kFile.read(4)
  201.  
  202. kData=kFile.read()
  203. return marshal.loads(kData)
  204.  
  205. def execfile(fileName, dict):
  206. kPE=PythonExecutioner()
  207. kPE.Run(fileName, dict)
  208.  
  209. def exec_add_module_do(mod):
  210. global execfile
  211. mod.__dict__['execfile'] = execfile
  212.  
  213. import __builtin__
  214. __builtin__.__import__ = __pack_import
  215. module_do = exec_add_module_do
  216.  
  217. """
  218. #
  219. # PSYCO installation (must move to system.py, systemrelease.pyc)
  220. #
  221. try:
  222. import psyco
  223. #from psyco.classes import *
  224.  
  225. def bind_me(bindable_list):
  226. try:
  227. for x in bindable_list:
  228. try:
  229. psyco.bind(x)
  230. except:
  231. pass
  232. except:
  233. pass
  234.  
  235. _prev_psyco_old_module_do = module_do
  236. def module_bind(module):
  237. _prev_psyco_old_module_do(module)
  238. #print 'start binding' + str(module)
  239. try:
  240. psyco.bind(module)
  241. except:
  242. pass
  243. for x in module.__dict__.itervalues():
  244. try:
  245. psyco.bind(x)
  246. except:
  247. pass
  248. #print 'end binding'
  249.  
  250. dbg.Trace("PSYCO installed\\n")
  251.  
  252. except Exception, msg:
  253. bind_me = lambda x:None
  254. dbg.Trace("No PSYCO support : %s\\n" % msg)
  255. """
  256.  
  257. def GetExceptionString(excTitle):
  258. (excType, excMsg, excTraceBack)=sys.exc_info()
  259. excText=""
  260. excText+=_chr(10)
  261.  
  262. import traceback
  263. traceLineList=traceback.extract_tb(excTraceBack)
  264.  
  265. for traceLine in traceLineList:
  266. if traceLine[3]:
  267. excText+="%s(line:%d) %s - %s" % (traceLine[0], traceLine[1], traceLine[2], traceLine[3])
  268. else:
  269. excText+="%s(line:%d) %s" % (traceLine[0], traceLine[1], traceLine[2])
  270.  
  271. excText+=_chr(10)
  272.  
  273. excText+=_chr(10)
  274. excText+="%s - %s:%s" % (excTitle, excType, excMsg)
  275. excText+=_chr(10)
  276.  
  277. return excText
  278.  
  279. def ShowException(excTitle):
  280. excText=GetExceptionString(excTitle)
  281. dbg.TraceError(excText)
  282. app.Abort()
  283.  
  284. return 0
  285.  
  286. def RunMainScript(name):
  287. try:
  288. execfile(name, __main__.__dict__)
  289. except RuntimeError, msg:
  290. msg = str(msg)
  291.  
  292. import locale
  293. if locale.error:
  294. msg = locale.error.get(msg, msg)
  295.  
  296. dbg.LogBox(msg)
  297. app.Abort()
  298.  
  299. except:
  300. msg = GetExceptionString("Run")
  301. dbg.LogBox(msg)
  302. app.Abort()
  303.  
  304. import debugInfo
  305. debugInfo.SetDebugMode(__DEBUG__)
  306.  
  307. loginMark = "-cs"
  308.  
  309. app.__COMMAND_LINE__ = __COMMAND_LINE__
  310. RunMainScript("prototype.py")
Advertisement
RAW Paste Data Copied
Advertisement