• Main Page
  • Namespaces
  • Classes
  • Files
  • File List

/home/mark/model/software/ScrumPy/ScrumPy/Util/File.py

00001 
00002 
00003 """
00004 
00005 ScrumPy -- Metabolic Modelling with Python
00006 
00007 Copyright Mark Poolman 1995 - 2002
00008 
00009  This file is part of ScrumPy.
00010 
00011     ScrumPy is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     ScrumPy is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU General Public License for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with ScrumPy; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025 """
00026 import os
00027 
00028 def IsYounger(FName1, FName2):
00029     """pre: Exists(FName1) and Exists(FName2)
00030     post : returns boolean indicating FName1 has more recent modification time than FName2 """
00031 
00032     return os.stat(FName1)[8] > os.stat(FName2)[8]
00033 
00034 def IsAbsPath(FName):
00035     """ pre: type(FName) == <type 'string'>
00036        post: IsAbsPath(FName) => FNames is an absolute (aot a relative) path name """
00037 
00038     return FName[0] == "/"
00039 
00040 def FindIn(Paths, targ):
00041     """ pre: Paths is a list of paths
00042        post: FindIn(Paths, targ) list of unique paths, rooted in Paths, containing targ"""
00043 
00044     rv = []
00045     seen = []
00046     def GotTarg(Targ_List, d, files):
00047         "Targ_List is (targ,list) tuple"
00048         if Targ_List[0] in files:
00049             Targ_List[1].append(d)
00050 
00051     Paths.sort(lambda x,y: len(x) - len(y))
00052     for p in Paths:
00053         OK = 1 
00054         for s in seen:
00055             if p.startswith(s):
00056                 OK = 0
00057         
00058         if OK:
00059             seen.append(p)
00060             os.path.walk(p, GotTarg, (targ,rv))
00061             
00062     return rv
00063 
00064     
00065        

Generated on Tue Sep 4 2012 15:38:02 for ScrumPy by  doxygen 1.7.1