00001 import os, sys 00002 import traceback 00003 00004 from vyperlogix.misc import _utils 00005 from vyperlogix.hash import lists 00006 00007 _metadata = lists.HashedLists2() 00008 00009 def getDaemons(prefix, fpath): 00010 import re 00011 from vyperlogix import misc 00012 _name = misc.funcName() 00013 s_regex = r".+%s\.((py)|(pyc)|(pyo))" % ('_tasklet') 00014 s_svn_regex = '[._]svn' 00015 _regex = re.compile(s_regex) 00016 svn_regex = re.compile(s_svn_regex) 00017 files = [f for f in os.listdir(os.path.abspath(fpath)) if _regex.search(f)] 00018 rejects = [f for f in os.listdir(os.path.abspath(fpath)) if (not _regex.search(f)) and (not svn_regex.search(f)) and (f.find('__init__.') == -1) and (f.find('dlib') == -1)] 00019 if (len(rejects) > 0): 00020 print >>sys.stderr, '(%s) :: Rejected daemon files are "%s" using (not "%s") and (not "%s"). PLS check the file names to ensure your daemons will be executed as planned.' % (_name,rejects,s_regex,s_svn_regex) 00021 return files 00022 00023 def getNormalizedDaemons(prefix, fpath): 00024 h = lists.HashedLists() 00025 00026 fs = [] 00027 dms = getDaemons(prefix, fpath) 00028 for f in dms: 00029 h[f.split('.')[0]] = f.split('.')[-1] 00030 for k,v in h.iteritems(): 00031 x = [n for n in v if n == 'py'] 00032 if (len(x) == 0): 00033 x = [n for n in v if n == 'pyc'] 00034 if (len(x) == 0): 00035 x = [n for n in v if n == 'pyo'] 00036 if (len(x) > 0): 00037 fs.append('.'.join([k,x[0]])) 00038 return fs 00039 00040 def getNormalizedDaemonNamespaces(prefix, fpath): 00041 return [f.split('.')[0] for f in getNormalizedDaemons(prefix, fpath)] 00042 00043 def execDaemon(f, dpath=None, _logging=None): 00044 _import_error = False 00045 try: 00046 exec "import " + f 00047 except ImportError: 00048 _import_error = True 00049 exc_info = sys.exc_info() 00050 info_string = '\n'.join(traceback.format_exception(*exc_info)) 00051 if (_logging): 00052 _logging.error(info_string) 00053 else: 00054 print >>sys.stderr, info_string 00055 00056 info_string = '_import_error=%s' % _import_error 00057 if (_logging): 00058 _logging.warning(info_string) 00059 else: 00060 print >>sys.stderr, info_string 00061 00062 if (not _import_error): 00063 _metadata[f] = lists.HashedLists2() 00064 try: 00065 v = '%s._metadata' % (f) 00066 vv = eval(v) 00067 print '%s=[%s]' % (v,vv) 00068 _metadata[f] = lists.HashedLists2(vv) 00069 v = '%s.data_hook("%s")' % (f,dpath if (sys.platform[:3] != 'win') else dpath.replace(os.sep,'/')) 00070 vv = eval(v) 00071 print '%s=[%s]' % (v,vv) 00072 except AttributeError: 00073 pass 00074 except ImportError: 00075 exc_info = sys.exc_info() 00076 info_string = '\n'.join(traceback.format_exception(*exc_info)) 00077 if (_logging): 00078 _logging.error(info_string) 00079 else: 00080 print >>sys.stderr, info_string 00081 00082 def execDaemons(prefix, fpath, dpath=None, _logging=None): 00083 for f in getNormalizedDaemonNamespaces(prefix, fpath): 00084 execDaemon("%s.%s" % (prefix,f.split('.')[0]), dpath=dpath, _logging=_logging) 00085 00086 00087
© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."
Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.
122,241 lines of code and growing...