Jason Tackaberry a écrit :
On Wed, 2007-01-03 at 12:37 +0100, Dirk Meyer wrote:
Maybe one idea would be to function to get all python files in a dir
as dict: name_without_suffix: name_with_suffix. So we could start
dict['main'] or interate over all python files.

It'd be easier (and probably faster) just to check to see if the files
exist when you want to run it.  If you want to run foo, check for
foo.pyo, then foo.pyc if it doesn't exist, then foo.py if it doesn't
exist.


Currently, I use this attached patch (only freevo, I look still for Kaa)
for keep only the .pyc (or pyo). Just the configfile.py must be kept.
It works, but surely than there is a better way.

Mathieu
Index: ui/contrib/developer/chktab.py
===================================================================
--- a/ui/contrib/developer/chktab.py    (révision 8918)
--- b/ui/contrib/developer/chktab.py    (copie de travail)
@@ -6,7 +6,9 @@
 def scandir(tabfiles, dirname, fnames):
 
     for fname in fnames:
-        if os.path.splitext(fname)[1] != '.py':
+        if os.path.splitext(fname)[1] != '.pyo' \
+        or os.path.splitext(fname)[1] != '.pyc' \
+        or os.path.splitext(fname)[1] != '.py':
             continue
 
         fullname = dirname + '/' + fname
Index: ui/src/gui/areas/handler.py
===================================================================
--- a/ui/src/gui/areas/handler.py       (révision 8918)
--- b/ui/src/gui/areas/handler.py       (copie de travail)
@@ -66,8 +66,11 @@
 # areas
 from default_areas  import *
 for f in os.listdir(os.path.dirname(__file__)):
-    if f.endswith('_area.py'):
-        exec('from %s import *' % f[:-3])
+    if f.endswith('_area.pyo') \
+    or f.endswith('_area.pyc'):
+        exec('from %s import *' % f[:-4])
+    if f.endswith('_area.py'):
+        exec('from %s import *' % f[:-3])
 
 
 class Handler(object):
Index: ui/src/config/configfile.py
===================================================================
--- a/ui/src/config/configfile.py       (révision 8918)
--- b/ui/src/config/configfile.py       (copie de travail)
@@ -71,7 +71,9 @@
 #
 for dirname in cfgfilepath[1:]:
     freevoconf = dirname + '/freevo_config.py'
-    if os.path.isfile(freevoconf):
+    if os.path.isfile(freevoconf + 'o') \
+    or os.path.isfile(freevoconf + 'c') \
+    or os.path.isfile(freevoconf):
         log.critical(('freevo_config.py found in %s, please remove it ' +
                       'and use local_conf.py instead!') % freevoconf)
         sys.exit(1)
@@ -80,7 +82,9 @@
 # Load freevo_config.py:
 #
 FREEVO_CONFIG = os.path.join(freevo.conf.SHAREDIR, 'freevo_config.py')
-if os.path.isfile(FREEVO_CONFIG):
+if os.path.isfile(FREEVO_CONFIG + 'o') \
+or os.path.isfile(FREEVO_CONFIG + 'c') \
+or os.path.isfile(FREEVO_CONFIG):
     log.info('Loading cfg: %s' % FREEVO_CONFIG)
     execfile(FREEVO_CONFIG, globals(), locals())
     
@@ -105,7 +109,9 @@
         overridefile = has_config
     else:
         overridefile = dirname + '/local_conf.py'
-    if os.path.isfile(overridefile):
+    if os.path.isfile(overridefile + 'o') \
+    or os.path.isfile(overridefile + 'c') \
+    or os.path.isfile(overridefile):
         log.info('Loading cfg overrides: %s' % overridefile)
         execfile(overridefile, globals(), locals())
 
Index: ui/src/plugin_loader.py
===================================================================
--- a/ui/src/plugin_loader.py   (révision 8918)
--- b/ui/src/plugin_loader.py   (copie de travail)
@@ -228,7 +228,9 @@
         """
         full_filename = os.path.join(self.path, filename)
 
-        if os.path.isfile(full_filename + '.py'):
+        if os.path.isfile(full_filename + '.pyo') \
+        or os.path.isfile(full_filename + '.pyc') \
+        or os.path.isfile(full_filename + '.py'):
             return filename.replace('/', '.'), None
 
         if os.path.isdir(full_filename):
@@ -236,7 +238,9 @@
 
         full_filename = os.path.join(self.path, 'plugins', filename)
 
-        if os.path.isfile(full_filename + '.py'):
+        if os.path.isfile(full_filename + '.pyo') \
+        or os.path.isfile(full_filename + '.pyc') \
+        or os.path.isfile(full_filename + '.py'):
             return 'plugins.' + filename.replace('/', '.'), None
 
         if os.path.isdir(full_filename):
@@ -248,7 +252,9 @@
                                     filename[filename.find('/')+1:])
             full_filename = os.path.join(self.path, filename)
 
-            if os.path.isfile(full_filename + '.py'):
+            if os.path.isfile(full_filename + '.pyo') \
+            or os.path.isfile(full_filename + '.pyc') \
+            or os.path.isfile(full_filename + '.py'):
                 return filename.replace('/', '.'), special
 
             if os.path.isdir(full_filename):
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Reply via email to