public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] portage r15450 - in main/trunk/pym/portage: . dbapi util
@ 2010-02-25  5:15 Zac Medico (zmedico)
  0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2010-02-25  5:15 UTC (permalink / raw
  To: gentoo-commits

Author: zmedico
Date: 2010-02-25 05:15:09 +0000 (Thu, 25 Feb 2010)
New Revision: 15450

Added:
   main/trunk/pym/portage/util/listdir.py
Modified:
   main/trunk/pym/portage/__init__.py
   main/trunk/pym/portage/dbapi/bintree.py
   main/trunk/pym/portage/dbapi/porttree.py
   main/trunk/pym/portage/dbapi/vartree.py
   main/trunk/pym/portage/util/digraph.py
Log:
Move cacheddir and listdir to portage.util.listdir.


Modified: main/trunk/pym/portage/__init__.py
===================================================================
--- main/trunk/pym/portage/__init__.py	2010-02-25 04:32:14 UTC (rev 15449)
+++ main/trunk/pym/portage/__init__.py	2010-02-25 05:15:09 UTC (rev 15450)
@@ -122,6 +122,7 @@
 			'stack_lists,unique_array,varexpand,writedict,writemsg,' + \
 			'writemsg_stdout,write_atomic',
 		'portage.util.digraph:digraph',
+		'portage.util.listdir:cacheddir,listdir',
 		'portage.versions',
 		'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,' + \
 			'cpv_getkey@getCPFromCPV,endversion_keys,' + \
@@ -533,145 +534,6 @@
 		mylink=mydir+"/"+mylink
 	return os.path.normpath(mylink)
 
-dircache = {}
-cacheHit=0
-cacheMiss=0
-cacheStale=0
-def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymlinks=True):
-	global cacheHit,cacheMiss,cacheStale
-	mypath = normalize_path(my_original_path)
-	if mypath in dircache:
-		cacheHit += 1
-		cached_mtime, list, ftype = dircache[mypath]
-	else:
-		cacheMiss += 1
-		cached_mtime, list, ftype = -1, [], []
-	try:
-		pathstat = os.stat(mypath)
-		if stat.S_ISDIR(pathstat[stat.ST_MODE]):
-			mtime = pathstat.st_mtime
-		else:
-			raise portage.exception.DirectoryNotFound(mypath)
-	except EnvironmentError as e:
-		if e.errno == portage.exception.PermissionDenied.errno:
-			raise portage.exception.PermissionDenied(mypath)
-		del e
-		return [], []
-	except portage.exception.PortageException:
-		return [], []
-	# Python retuns mtime in seconds, so if it was changed in the last few seconds, it could be invalid
-	if mtime != cached_mtime or time.time() - mtime < 4:
-		if mypath in dircache:
-			cacheStale += 1
-		try:
-			list = os.listdir(mypath)
-		except EnvironmentError as e:
-			if e.errno != errno.EACCES:
-				raise
-			del e
-			raise portage.exception.PermissionDenied(mypath)
-		ftype = []
-		for x in list:
-			try:
-				if followSymlinks:
-					pathstat = os.stat(mypath+"/"+x)
-				else:
-					pathstat = os.lstat(mypath+"/"+x)
-
-				if stat.S_ISREG(pathstat[stat.ST_MODE]):
-					ftype.append(0)
-				elif stat.S_ISDIR(pathstat[stat.ST_MODE]):
-					ftype.append(1)
-				elif stat.S_ISLNK(pathstat[stat.ST_MODE]):
-					ftype.append(2)
-				else:
-					ftype.append(3)
-			except (IOError, OSError):
-				ftype.append(3)
-		dircache[mypath] = mtime, list, ftype
-
-	ret_list = []
-	ret_ftype = []
-	for x in range(0, len(list)):
-		if list[x] in ignorelist:
-			pass
-		elif ignorecvs:
-			if list[x][:2] != ".#":
-				ret_list.append(list[x])
-				ret_ftype.append(ftype[x])
-		else:
-			ret_list.append(list[x])
-			ret_ftype.append(ftype[x])
-
-	writemsg("cacheddirStats: H:%d/M:%d/S:%d\n" % (cacheHit, cacheMiss, cacheStale),10)
-	return ret_list, ret_ftype
-
-_ignorecvs_dirs = ('CVS', 'SCCS', '.svn', '.git')
-
-def listdir(mypath, recursive=False, filesonly=False, ignorecvs=False, ignorelist=[], followSymlinks=True,
-	EmptyOnError=False, dirsonly=False):
-	"""
-	Portage-specific implementation of os.listdir
-
-	@param mypath: Path whose contents you wish to list
-	@type mypath: String
-	@param recursive: Recursively scan directories contained within mypath
-	@type recursive: Boolean
-	@param filesonly; Only return files, not more directories
-	@type filesonly: Boolean
-	@param ignorecvs: Ignore CVS directories ('CVS','SCCS','.svn','.git')
-	@type ignorecvs: Boolean
-	@param ignorelist: List of filenames/directories to exclude
-	@type ignorelist: List
-	@param followSymlinks: Follow Symlink'd files and directories
-	@type followSymlinks: Boolean
-	@param EmptyOnError: Return [] if an error occurs (deprecated, always True)
-	@type EmptyOnError: Boolean
-	@param dirsonly: Only return directories.
-	@type dirsonly: Boolean
-	@rtype: List
-	@returns: A list of files and directories (or just files or just directories) or an empty list.
-	"""
-
-	list, ftype = cacheddir(mypath, ignorecvs, ignorelist, EmptyOnError, followSymlinks)
-
-	if list is None:
-		list=[]
-	if ftype is None:
-		ftype=[]
-
-	if not (filesonly or dirsonly or recursive):
-		return list
-
-	if recursive:
-		x=0
-		while x<len(ftype):
-			if ftype[x] == 1 and not \
-				(ignorecvs and os.path.basename(list[x]) in _ignorecvs_dirs):
-				l,f = cacheddir(mypath+"/"+list[x], ignorecvs, ignorelist, EmptyOnError,
-					followSymlinks)
-
-				l=l[:]
-				for y in range(0,len(l)):
-					l[y]=list[x]+"/"+l[y]
-				list=list+l
-				ftype=ftype+f
-			x+=1
-	if filesonly:
-		rlist=[]
-		for x in range(0,len(ftype)):
-			if ftype[x]==0:
-				rlist=rlist+[list[x]]
-	elif dirsonly:
-		rlist = []
-		for x in range(0, len(ftype)):
-			if ftype[x] == 1:
-				rlist = rlist + [list[x]]	
-	else:
-		rlist=list
-
-	return rlist
-
 #parse /etc/env.d and generate /etc/profile.env
 
 def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,

Modified: main/trunk/pym/portage/dbapi/bintree.py
===================================================================
--- main/trunk/pym/portage/dbapi/bintree.py	2010-02-25 04:32:14 UTC (rev 15449)
+++ main/trunk/pym/portage/dbapi/bintree.py	2010-02-25 05:15:09 UTC (rev 15450)
@@ -13,6 +13,7 @@
 	'portage.package.ebuild.doebuild:_vdb_use_conditional_atoms',
 	'portage.update:update_dbentries',
 	'portage.util:ensure_dirs,normalize_path,writemsg,writemsg_stdout',
+	'portage.util.listdir:listdir',
 	'portage.versions:best,catpkgsplit,catsplit',
 )
 
@@ -22,7 +23,7 @@
 	PermissionDenied, PortageException
 from portage.localization import _
 
-from portage import dep_expand, listdir, _movefile
+from portage import dep_expand, _movefile
 from portage import os
 from portage import _encodings
 from portage import _unicode_decode

Modified: main/trunk/pym/portage/dbapi/porttree.py
===================================================================
--- main/trunk/pym/portage/dbapi/porttree.py	2010-02-25 04:32:14 UTC (rev 15449)
+++ main/trunk/pym/portage/dbapi/porttree.py	2010-02-25 05:15:09 UTC (rev 15450)
@@ -11,9 +11,11 @@
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
 	'portage.checksum',
-	'portage.dep:dep_getkey,match_from_list,paren_reduce,use_reduce',
+	'portage.dep:dep_getkey,flatten,match_from_list,paren_reduce,use_reduce',
 	'portage.env.loaders:KeyValuePairFileLoader',
+	'portage.package.ebuild.doebuild:doebuild',
 	'portage.util:ensure_dirs,writemsg,writemsg_level',
+	'portage.util.listdir:listdir',
 	'portage.versions:best,catpkgsplit,_pkgsplit@pkgsplit,ver_regexp',
 )
 
@@ -27,8 +29,8 @@
 from portage.localization import _
 from portage.manifest import Manifest
 
-from portage import eclass_cache, auxdbkeys, doebuild, flatten, \
-	listdir, dep_expand, eapi_is_supported, dep_check, \
+from portage import eclass_cache, auxdbkeys, \
+	dep_expand, eapi_is_supported, dep_check, \
 	_eapi_is_deprecated
 from portage import os
 from portage import _encodings

Modified: main/trunk/pym/portage/dbapi/vartree.py
===================================================================
--- main/trunk/pym/portage/dbapi/vartree.py	2010-02-25 04:32:14 UTC (rev 15449)
+++ main/trunk/pym/portage/dbapi/vartree.py	2010-02-25 05:15:09 UTC (rev 15450)
@@ -11,7 +11,7 @@
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
 	'portage.checksum:_perform_md5_merge@perform_md5',
-	'portage.dep:dep_getkey,isjustname,match_from_list,' + \
+	'portage.dep:dep_getkey,isjustname,flatten,match_from_list,' + \
 	 	'use_reduce,paren_reduce,_slot_re',
 	'portage.elog:elog_process',
 	'portage.locks:lockdir,unlockdir',
@@ -23,7 +23,10 @@
 	'portage.util:apply_secpass_permissions,ConfigProtect,ensure_dirs,' + \
 		'writemsg,writemsg_level,write_atomic,atomic_ofstream,writedict,' + \
 		'grabfile,grabdict,normalize_path,new_protect_filename,getlibpaths',
-	'portage.versions:best,catpkgsplit,catsplit,pkgcmp,_pkgsplit@pkgsplit',
+	'portage.util.digraph:digraph',
+	'portage.util.listdir:dircache,listdir',
+	'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,pkgcmp,' + \
+		'_pkgsplit@pkgsplit',
 )
 
 from portage.const import CACHE_PATH, CONFIG_MEMORY_FILE, \
@@ -35,9 +38,8 @@
 	FileNotFound, PermissionDenied, UnsupportedAPIException
 from portage.localization import _
 
-from portage import listdir, dep_expand, digraph, flatten, \
-	env_update, \
-	abssymlink, movefile, _movefile, bsd_chflags, cpv_getkey
+from portage import dep_expand, env_update, \
+	abssymlink, movefile, _movefile, bsd_chflags
 
 # This is a special version of the os module, wrapped for unicode support.
 from portage import os
@@ -1086,7 +1088,6 @@
 		self.mtdircache.pop(pkg_dblink.cat, None)
 		self.matchcache.pop(pkg_dblink.cat, None)
 		self.cpcache.pop(pkg_dblink.mysplit[0], None)
-		from portage import dircache
 		dircache.pop(pkg_dblink.dbcatdir, None)
 
 	def match(self, origdep, use_cache=1):

Modified: main/trunk/pym/portage/util/digraph.py
===================================================================
--- main/trunk/pym/portage/util/digraph.py	2010-02-25 04:32:14 UTC (rev 15449)
+++ main/trunk/pym/portage/util/digraph.py	2010-02-25 05:15:09 UTC (rev 15450)
@@ -2,6 +2,8 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Id$
 
+__all__ = ['digraph']
+
 from portage.util import writemsg
 
 class digraph(object):

Added: main/trunk/pym/portage/util/listdir.py
===================================================================
--- main/trunk/pym/portage/util/listdir.py	                        (rev 0)
+++ main/trunk/pym/portage/util/listdir.py	2010-02-25 05:15:09 UTC (rev 15450)
@@ -0,0 +1,153 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+__all__ = ['cacheddir', 'listdir']
+
+import errno
+import stat
+import time
+
+from portage import os
+from portage.exception import DirectoryNotFound, PermissionDenied, PortageException
+from portage.util import normalize_path, writemsg
+
+dircache = {}
+cacheHit = 0
+cacheMiss = 0
+cacheStale = 0
+
+def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymlinks=True):
+	global cacheHit,cacheMiss,cacheStale
+	mypath = normalize_path(my_original_path)
+	if mypath in dircache:
+		cacheHit += 1
+		cached_mtime, list, ftype = dircache[mypath]
+	else:
+		cacheMiss += 1
+		cached_mtime, list, ftype = -1, [], []
+	try:
+		pathstat = os.stat(mypath)
+		if stat.S_ISDIR(pathstat[stat.ST_MODE]):
+			mtime = pathstat.st_mtime
+		else:
+			raise DirectoryNotFound(mypath)
+	except EnvironmentError as e:
+		if e.errno == PermissionDenied.errno:
+			raise PermissionDenied(mypath)
+		del e
+		return [], []
+	except PortageException:
+		return [], []
+	# Python retuns mtime in seconds, so if it was changed in the last few seconds, it could be invalid
+	if mtime != cached_mtime or time.time() - mtime < 4:
+		if mypath in dircache:
+			cacheStale += 1
+		try:
+			list = os.listdir(mypath)
+		except EnvironmentError as e:
+			if e.errno != errno.EACCES:
+				raise
+			del e
+			raise PermissionDenied(mypath)
+		ftype = []
+		for x in list:
+			try:
+				if followSymlinks:
+					pathstat = os.stat(mypath+"/"+x)
+				else:
+					pathstat = os.lstat(mypath+"/"+x)
+
+				if stat.S_ISREG(pathstat[stat.ST_MODE]):
+					ftype.append(0)
+				elif stat.S_ISDIR(pathstat[stat.ST_MODE]):
+					ftype.append(1)
+				elif stat.S_ISLNK(pathstat[stat.ST_MODE]):
+					ftype.append(2)
+				else:
+					ftype.append(3)
+			except (IOError, OSError):
+				ftype.append(3)
+		dircache[mypath] = mtime, list, ftype
+
+	ret_list = []
+	ret_ftype = []
+	for x in range(0, len(list)):
+		if list[x] in ignorelist:
+			pass
+		elif ignorecvs:
+			if list[x][:2] != ".#":
+				ret_list.append(list[x])
+				ret_ftype.append(ftype[x])
+		else:
+			ret_list.append(list[x])
+			ret_ftype.append(ftype[x])
+
+	writemsg("cacheddirStats: H:%d/M:%d/S:%d\n" % (cacheHit, cacheMiss, cacheStale),10)
+	return ret_list, ret_ftype
+
+_ignorecvs_dirs = ('CVS', 'SCCS', '.svn', '.git')
+
+def listdir(mypath, recursive=False, filesonly=False, ignorecvs=False, ignorelist=[], followSymlinks=True,
+	EmptyOnError=False, dirsonly=False):
+	"""
+	Portage-specific implementation of os.listdir
+
+	@param mypath: Path whose contents you wish to list
+	@type mypath: String
+	@param recursive: Recursively scan directories contained within mypath
+	@type recursive: Boolean
+	@param filesonly; Only return files, not more directories
+	@type filesonly: Boolean
+	@param ignorecvs: Ignore CVS directories ('CVS','SCCS','.svn','.git')
+	@type ignorecvs: Boolean
+	@param ignorelist: List of filenames/directories to exclude
+	@type ignorelist: List
+	@param followSymlinks: Follow Symlink'd files and directories
+	@type followSymlinks: Boolean
+	@param EmptyOnError: Return [] if an error occurs (deprecated, always True)
+	@type EmptyOnError: Boolean
+	@param dirsonly: Only return directories.
+	@type dirsonly: Boolean
+	@rtype: List
+	@returns: A list of files and directories (or just files or just directories) or an empty list.
+	"""
+
+	list, ftype = cacheddir(mypath, ignorecvs, ignorelist, EmptyOnError, followSymlinks)
+
+	if list is None:
+		list=[]
+	if ftype is None:
+		ftype=[]
+
+	if not (filesonly or dirsonly or recursive):
+		return list
+
+	if recursive:
+		x=0
+		while x<len(ftype):
+			if ftype[x] == 1 and not \
+				(ignorecvs and os.path.basename(list[x]) in _ignorecvs_dirs):
+				l,f = cacheddir(mypath+"/"+list[x], ignorecvs, ignorelist, EmptyOnError,
+					followSymlinks)
+
+				l=l[:]
+				for y in range(0,len(l)):
+					l[y]=list[x]+"/"+l[y]
+				list=list+l
+				ftype=ftype+f
+			x+=1
+	if filesonly:
+		rlist=[]
+		for x in range(0,len(ftype)):
+			if ftype[x]==0:
+				rlist=rlist+[list[x]]
+	elif dirsonly:
+		rlist = []
+		for x in range(0, len(ftype)):
+			if ftype[x] == 1:
+				rlist = rlist + [list[x]]	
+	else:
+		rlist=list
+
+	return rlist


Property changes on: main/trunk/pym/portage/util/listdir.py
___________________________________________________________________
Added: svn:keywords
   + Id




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-02-25  5:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-25  5:15 [gentoo-commits] portage r15450 - in main/trunk/pym/portage: . dbapi util Zac Medico (zmedico)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox