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 Details

class cs.directory

A directory.

__cmp__(other)

Comparison function for directory .

Parameters:other (directory) – The directory object 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) – The directory to compare against.
Return type:bool
Returns:True if self and b compare equal, False otherwise.
>>> rds = project.current().root_directories()
>>> d = next(rds)
>>> d == d
True
__ge__(b)

Greater-than-or-equal operator for directory .

Parameters:b (directory) – The directory to compare against.
Return type:bool
Returns:True if self >= b , False otherwise.
>>> rds = project.current().root_directories()
>>> d = next(rds)
>>> d2 = next(rds)
>>> d >= d2
False
__gt__(b)

Greater-than operator for directory .

Parameters:b (directory) – The directory to compare against.
Return type:bool
Returns:True if self > b , False otherwise.
>>> 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) – The directory to compare against.
Return type:bool
Returns:True if self <= b , False otherwise.
>>> rds = project.current().root_directories()
>>> d = next(rds)
>>> d2 = next(rds)
>>> d <= d2
True
__lt__(b)

Less-than operator for directory .

Parameters:b (directory) – The directory to compare against.
Return type:bool
Returns:True if self < b , False otherwise.
>>> rds = project.current().root_directories()
>>> d = next(rds)
>>> d2 = next(rds)
>>> d <= d2
True
__ne__(b)

Inequality operator for directory .

Parameters:b (directory) – The directory to compare against.
Return type:bool
Returns:False if self and b compare equal, True otherwise.
>>> rds = project.current().root_directories()
>>> d = next(rds)
>>> d2 = next(rds)
>>> d != d2
True
__repr__()

Get a representation of a directory object 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 directory object.

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_iterator
Returns: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_iterator
Returns: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'
parent()

Get the parent directory of a directory.

Return type:directory
Returns:The parent directory.
Raises:result.ELEMENT_NOT_PRESENT if self has 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) – The directory to compare against.
Return type:int
Returns:An integer N such that:
  • N<0 if self considered less than other
  • N==0 if and other have the same normalized directory path as determined by directory.normalized_name().
  • N>0 if self considered greater than other

This function is provided so directory objects 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 directory objects in A1, and a2 and b2 be the directory objects 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
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 directory object in A1, and b2 be the directory object 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