Module ytfs
¶
Main module of YTFS. Executing this module causes YTFS filesystem mount in given directory.
-
class
ytfs.ytfs.
YTFS
[source]¶ Main YTFS class.
Attributes
st (dict) Dictionary that contains basic file attributes. Consult man 2 stat
for reference.searches (dict) Dictionary that is a main interface to data of idividual searches and their results (movies) stored by filesystem. Format: searches = { ‘search phrase 1’: YTActions({ ‘tytul1’: <YTStor obj>, ‘tytul2’: <YTStor obj>, ... }), ‘search phrase 2’: YTActions({ ... }), ... } YTStor
object stores all needed information about movie, not only multimedia data. Attention: for simplicity, file extensions are present only during directory listing. In all other operations extensions are dropped.fds (fd_dict) fd_dict
dictionary which links descriptors in use with correspondingYTStor
objects. Key: descriptor. Value:YTStor
object for given file.__sh_script (bytes) Control file contents. -
class
PathType
[source]¶ Human readable representation of path type of given tuple identifier.
Attributes
invalid (int) Invalid path. main (int) Main directory. subdir (int) Subdirectory (search directory). file (int) File (search result). ctrl (int) Control file.
-
YTFS.
_YTFS__exists
(p)¶ Check if file of given path exists.
Parameters: p : str or tuple
Path or tuple identifier.
Returns: exists : bool
True
, if file exists. OtherwiseFalse
.
-
YTFS.
_YTFS__pathToTuple
(path)¶ Convert directory or file path to its tuple identifier.
Parameters: path : str
Path to convert. It can look like /, /directory, /directory/ or /directory/filename.
Returns: tup_id : tuple
Two element tuple identifier of directory/file of (directory, filename) format. If path leads to main directory, then both fields of tuple will be
None
. If path leads to a directory, then field filename will beNone
.Raises: YTFS.PathConvertError
When invalid path is given.
-
YTFS.
_pathdec
(method)[source]¶ Decorator that replaces string path argument with its tuple identifier.
Parameters: method : function
Function/method to decorate.
Returns: mod : function
Function/method after decarotion.
-
YTFS.
getattr
(tid, fh=None)[source]¶ File attributes.
Parameters: tid : str
Path to file. Original path argument is converted to tuple identifier by
_pathdec
decorator.fh : int
File descriptor. Unnecessary, therefore ignored.
Returns: st : dict
Dictionary that contains file attributes. See:
man 2 stat
.
-
YTFS.
mkdir
(tid, mode)[source]¶ Directory creation. Search is performed.
Parameters: tid : str
Path to file. Original path argument is converted to tuple identifier by
_pathdec
decorator.mode : int
Ignored.
-
YTFS.
open
(tid, flags)[source]¶ File open.
YTStor
object associated with this file is initialised and written toself.fds
.Parameters: tid : str
Path to file. Original path argument is converted to tuple identifier by
_pathdec
decorator.flags : int
File open mode. Read-only access is allowed.
Returns: int
New file descriptor
-
YTFS.
read
(tid, length, offset, fh)[source]¶ Read from a file. Data is obtained from
YTStor
object (which is kept under fh descriptor) using itsread
method.Parameters: tid : str
Path to file. Original path argument is converted to tuple identifier by
_pathdec
decorator.length : int
Length of data to read.
offset : int
Posision from which reading will start.
fh : int
File descriptor.
Returns: bytes
Movie data.
-
YTFS.
readdir
(tid, fh)[source]¶ Read directory contents. Lists visible elements of
YTActions
object.Parameters: tid : str
Path to file. Original path argument is converted to tuple identifier by
_pathdec
decorator.fh : int
File descriptor. Ommited in the function body.
Returns: list
List of filenames, wich will be shown as directory content.
-
YTFS.
release
(tid, fh)[source]¶ Close file. Descriptor is removed from
self.fds
.Parameters: tid : str
Path to file. Ignored.
fh : int
File descriptor to release.
-
YTFS.
rename
(old, new)[source]¶ Directory renaming support. Needed because many file managers create directories with default names, wich makes it impossible to perform a search without CLI. Name changes for files are not allowed, only for directories.
Parameters: old : str
Old name. Converted to tuple identifier by
_pathdec
decorator.new : str
New name. Converted to tuple identifier in actual function body.
-
YTFS.
rmdir
(tid)[source]¶ Directory removal.
YTActions
object under tid is told to clean all data, and then it is deleted.Parameters: tid : str
Path to file. Original path argument is converted to tuple identifier by
_pathdec
decorator.
-
YTFS.
unlink
(tid)[source]¶ File removal. In fact nothing is deleted, but for correct
rm -r
handling we deceive shell, that function has succeed.Parameters: tid : str
Path to file. Original path argument is converted to tuple identifier by
_pathdec
decorator.
-
YTFS.
write
(tid, data, offset, fh)[source]¶ Write operation. Applicable only for control files - updateResults is called.
Parameters: tid : str
Path to file. Original path argument is converted to tuple identifier by
_pathdec
decorator.data : bytes
Ignored.
offset : int
Ignored.
fh : int
File descriptor.
Returns: int
Length of data written.
-
class