rql_download.twistedserver.server.VirtualPathTranslator¶
-
class
rql_download.twistedserver.server.
VirtualPathTranslator
(search_request)[source]¶ Responsible to translate virtual path into real one.
Suppose to be called from ‘CubicWebConchUser’ through the following methods:
- openDirectory
- getAttrs
- realPath
- openFile
Methods
__init__
(search_request)Initialize the ‘VirtualPathTranslator’ class. attrs_from_stat
(s)Convert a ‘posix.stat_result’ to python dictionary. dir_content
(virtpath, session_index)Get complete file paths of files located in a virtual directory. filter_files
(files, path)Extract files which are located in a directory defined by path. get_attrs
(path[, followlinks])Return the file state. get_attrs_file_entity
(binary)Get statistical information of a Binary field. is_file_entity
(virtpath)Check if the file is virtual, ie. list_directory
(path)Method to list a virtual folder. open_cw_file
(virtpath)Method used to open a virtual cubicweb file. real_path
(virtpath)Get the real path from a virtual path. split_virtual_path
(path)Extract the name of a Search Entity from path. stat
(path[, followlinks, path_is_real])Method to access a path state. stat_file_entity
([binary_len])Return the file state. Attributes
BASE_REAL_DIR
INSTANCE_NAMES
dir_perm
file_entity_re
file_perm
-
BASE_REAL_DIR
= '/'¶
-
INSTANCE_NAMES
= None¶
-
__module__
= 'rql_download.twistedserver.server'¶
-
attrs_from_stat
(s)[source]¶ Convert a ‘posix.stat_result’ to python dictionary.
Parameters: s: posix.stat_result (mandatory) :
the same structure returned by a stat or lstat.
Returns: out: dict :
a dictionary summarizing the input statistic structure: size - uid - gid - mtime - atime - permissions.
-
dir_content
(virtpath, session_index)[source]¶ Get complete file paths of files located in a virtual directory.
Parameters: virtpath: VirtualPath (mandatory) :
a virtual path of the form (search name, search relpath, search basedir, search instance).
session_index: int (mandatory) :
an index pointing to the instance of interest.
Returns: out: iterator :
each item is 2-uplet of the form (file path, associated rset).
-
dir_perm
= 17261¶
-
file_entity_re
= <_sre.SRE_Pattern object>¶
-
file_perm
= 33060¶
-
filter_files
(files, path)[source]¶ Extract files which are located in a directory defined by path.
Parameters: files: list of 2-uplet (mandatory) :
a list of files formated in a 2-uplet of the form (path, is_virtual).
path: string (mandatory) :
the associated dir real path.
Returns: out: iterator :
each item is 2-uplet of the form (file path, associated rset).
-
get_attrs
(path, followlinks=0)[source]¶ Return the file state.
Parameters: binary_len: int (mandatory) :
the size of the file.
Returns: out: stat_result :
the same structure returned by a stat or lstat.
-
get_attrs_file_entity
(binary)[source]¶ Get statistical information of a Binary field.
Parameters: binary: a Binary entity field (mandatory) :
a Binary object.
Returns: out: dict :
a dictionary summarizing the input statistic structure: size - uid - gid - mtime - atime - permissions.
-
is_file_entity
(virtpath)[source]¶ Check if the file is virtual, ie. a Binary cubicweb file.
Parameters: virtpath: VirtualPath (mandatory) :
a virtual path of the form (search name, search relpath, search basedir, search instance).
Returns: out: bool :
True if the virtualpath point to a cubicweb file, False otherwise.
-
list_directory
(path)[source]¶ Method to list a virtual folder.
Virtual folders have a common root organization:
instance name | ---- CWSearch name | ---- ...
Parameters: path: string (mandatory) :
the virtual path we want to access.
Returns: out: iterator :
an iterator containing virtual folder description. Each iterator item is a 3-uplet of the form (basename, longname, stat).
-
open_cw_file
(virtpath)[source]¶ Method used to open a virtual cubicweb file.
Parameters: virtpath: VirtualPath (mandatory) :
a virtual path of the form (search name, search relpath, search basedir, search instance).
Returns: out: CubicwebFile :
a virtual file containing the Binary field data.
-
real_path
(virtpath)[source]¶ Get the real path from a virtual path.
Simply concatenate the search basedir set in the configuration file with the search relpath.
Parameters: virtpath: VirtualPath (mandatory) :
a virtual path.
Returns: out: string :
the real path on the server.
-
split_virtual_path
(path)[source]¶ Extract the name of a Search Entity from path.
This name is expected to be the first part of path if no instance name are given, second one otherwise.
Parameters: path: string (mandatory) :
the virtual path we want to split.
Returns: out: VirtualPath :
the virtual path built from the input path, ie. a 4-uplet of the form (search name, search relpath, search basedir, search instance).
-
stat
(path, followlinks=0, path_is_real=False)[source]¶ Method to access a path state.
Parameters: path: str (mandatory) :
a path from which we want to get the associated statistics.
followlinks: int (optional, default 0) :
if True the system will follow the symbolic links with the ‘os.stat’ method, otherwise the ‘os.lstat’ method is used.
path_is_real: bool (optional, default False) :
if True the path really exists on the file system, otherwise we have a virtual cubicweb path.
Returns: out: posix.stat_result :
the same structure returned by a stat or lstat.