class directory¶
A directory.
The following are useful for retrieving directories.
| Class | Methods |
|---|---|
directory |
directory.children() (via a directory_children_iterator ) |
project |
project.root_directories() (via a project_root_directories_iterator ) |
sfile |
sfile.parent() |
directory Members¶
| Constructors | none |
| Methods | __cmp__(), __eq__(), __ge__(), __gt__(), __hash__(), __le__(), __lt__(), __ne__(), __repr__(), __str__(), child_count(), children(), depth(), file_count(), files(), name(), normalized_name(), parent(), stable_cmp(), stable_hash() |
directory Details¶
-
class
cs.directory¶ A directory.
-
__cmp__(other)¶ Comparison function for
directory.Parameters: other ( directory) – Thedirectoryobject to compare against.Return type: int Returns: An integer N such that: - N==0 if the two objects compare equal
- N<0 if
self< other - N>0 if
self> other
>>> v0 = project.current() >>> v1 = v0.root_directories() >>> v2 = next(v1) >>> v2.__cmp__(v2) 0
-
__eq__(b)¶ Equality operator for
directory.Parameters: b ( directory) – Thedirectoryto compare against.Return type: bool Returns: Trueifselfandbcompare equal,Falseotherwise.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d == d True
-
__ge__(b)¶ Greater-than-or-equal operator for
directory.Parameters: b ( directory) – Thedirectoryto compare against.Return type: bool Returns: Trueifself>=b,Falseotherwise.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d2 = next(rds) >>> d >= d2 False
-
__gt__(b)¶ Greater-than operator for
directory.Parameters: b ( directory) – Thedirectoryto compare against.Return type: bool Returns: Trueifself>b,Falseotherwise.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d2 = next(rds) >>> d > d2 False
-
__hash__()¶ Get a hash value for a
directory.Return type: int >>> rds = project.current().root_directories() >>> d = next(rds) >>> hash(d) 1089729214
-
__le__(b)¶ Less-than-or-equal operator for
directory.Parameters: b ( directory) – Thedirectoryto compare against.Return type: bool Returns: Trueifself<=b,Falseotherwise.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d2 = next(rds) >>> d <= d2 True
-
__lt__(b)¶ Less-than operator for
directory.Parameters: b ( directory) – Thedirectoryto compare against.Return type: bool Returns: Trueifself<b,Falseotherwise.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d2 = next(rds) >>> d <= d2 True
-
__ne__(b)¶ Inequality operator for
directory.Parameters: b ( directory) – Thedirectoryto compare against.Return type: bool Returns: Falseifselfandbcompare equal,Trueotherwise.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d2 = next(rds) >>> d != d2 True
-
__repr__()¶ Get a representation of a
directoryobject that includes information useful for debugging.Return type: str Returns: The string representation. >>> rds = project.current().root_directories() >>> d = next(rds) >>> repr(d) '<cs.directory C:\\Program Files\\CodeSecure\\CodeSonar>'
-
__str__()¶ Get a simple string representation of a
directoryobject.Return type: str Returns: The string representation. >>> rds = project.current().root_directories() >>> d = next(rds) >>> str(d) 'C:\\Program Files\\CodeSecure\\CodeSonar'
-
child_count()¶ Get the number of subdirectories.
Return type: int Returns: The number of subdirectories that contain source files. >>> rds = project.current().root_directories() >>> d = next(rds) >>> d.child_count() 1
-
children()¶ Get an iterator over the immediate subdirectories (
directory) of a directory.Return type: directory_children_iteratorReturns: The initialized directory_children_iterator.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d.children() <cs.directory_children_iterator begin>
-
depth()¶ Get the depth or distance from root of a directory.
Return type: int Returns: The directory depth. >>> rds = project.current().root_directories() >>> d = next(rds) >>> d.depth() 1
-
file_count()¶ Get the number of files.
Return type: int Returns: The number of source files in this directory. >>> rds = project.current().root_directories() >>> d = next(rds) >>> d.file_count() 0
-
files()¶ Get an iterator over the source files (
sfile) directly contained in a directory.Return type: directory_files_iteratorReturns: The initialized directory_files_iterator.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d.files() <cs.directory_files_iterator begin>
-
name()¶ Get the directory path associated with a directory.
Return type: str Returns: A string containing the path of the directory. >>> rds = project.current().root_directories() >>> d = next(rds) >>> d.name() 'C:\\Program Files\\CodeSecure\\CodeSonar'
-
normalized_name()¶ Get the normalized directory path associated with a directory.
Return type: str Returns: A string containing the path of the directory. - Windows: this string is the downcased version of the one returned by
directory.name(), with backslash directory separators replaced by forward slashes. - Mac: this string is the downcased version of the one returned by
directory.name(). - Otherwise: this string is the same as the one returned by
directory.name().
>>> rds = project.current().root_directories() >>> d = next(rds) >>> d.normalized_name() 'c:/program files/codesecure/codesonar'
- Windows: this string is the downcased version of the one returned by
-
parent()¶ Get the parent
directoryof a directory.Return type: directoryReturns: The parent directory. Raises: result.ELEMENT_NOT_PRESENTifselfhas no parent directory (i.e. is a root).>>> v0 = project.current() >>> v1 = v0.sfiles() >>> v2 = next(v1) >>> v3 = v2.parent() >>> v3.parent() <cs.directory /mys0/alex/trunk/csurf>
-
stable_cmp(other)¶ Comparison function for
directory, with stable results across sufficiently-similar analyses.Parameters: other ( directory) – Thedirectoryto compare against.Return type: int Returns: An integer N such that: - N<0 if
selfconsidered less thanother - N==0 if
andotherhave the same normalized directory path as determined bydirectory.normalized_name(). - N>0 if
selfconsidered greater thanother
This function is provided so
directoryobjects can be stored in ordered containers that provide stable iteration order.The comparison is stable in the following sense. Suppose there are two analyses A1 and A2 generated with exactly the same inputs (including identical analyzed code, underlying build commands and ordering, command line and configuration settings, increment order and contents). Let a1 and b1 be two
directoryobjects in A1, and a2 and b2 be thedirectoryobjects objects in A2 that correspond to a1 and b1 respectively. Then a1.stable_cmp(b1)==a2.stable_cmp(b2)If you do not need comparison results to be stable across different analyses, use
directory.__cmp__(): it has better performance.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d2 = next(rds) >>> d.stable_cmp(d2) 56
- N<0 if
-
stable_hash()¶ Get a hash value for a
directory, with stable results across sufficiently-similar analyses.Return type: int Returns: A hash derived from the directory. This hash value is stable in the following sense. Suppose there are two analyses A1 and A2 generated with exactly the same inputs (including identical analyzed code, underlying build commands and ordering, command line and configuration settings, increment order and contents). Let b1 be a
directoryobject in A1, and b2 be thedirectoryobject in A2 that corresponds to b1. Then b1.stable_hash()==b1.stable_hash().If you do not need hash values to be stable across analyses, use
directory.__hash__(): it has better performance.>>> rds = project.current().root_directories() >>> d = next(rds) >>> d.stable_hash() 1320131538
-