Commits

uniqx committed 079dfe7

added a TODO for ast; adapted function for reading text files

Comments (0)

Files changed (2)

 ^.*\.pyo$
 ^.*\.log$
 ^.*\.tar$
+^.*\.swp$
 import os
 import re
 import sys
+import ast
 import time
 import tarfile
 
   :param number mtime: new modification time
   '''
 
-  # unlad if already initialized
+  # TODO: use ast instead of recompiling the source for every exec
+  #
+  # p = ast.parse(src)
+  # if '''__pyld_init__''' in ast.dump(p.body[0].test):
+  #   exec(compile(ast.Module(p.body[0].body),'blaafoo.py','exec'))
+
+  # unload if already initialized
   if handle['init']:
     __name__ = '__pyld_unload__'
     exec(handle['content'])
     __name__ = '__main__'
 
   # (re)read the file
-  read_file(handle)
+  handle['content'] = read_text_file(handle['path'])
 
   # initialize if not yet initialized
   if not handle['init']:
   # archive
   if arch_path != '':
     try:
-      tar = tarfile.open(arch_path, "a")
+      tar = tarfile.open(arch_path, 'a')
       tar.add(name=handle['path'],arcname=__crop_name(handle['path'])+'.'+str(int(time.time()))+'.'+__crop_ext(handle['path']))
     finally:
       try:
         pass
 
 
-def read_file(handle):
+def read_text_file(path):
+  '''reads a text file and returns it as a string'''
 
-  with open(handle['path'],'r') as f:
-    handle['content']=''
+  ret = ''
+
+  with open(path,'r') as f:
     for line in f:
-      handle['content'] += line
+      ret += line
   f.closed
 
+  return ret
+
+
+
+
 if __name__ == '__main__':