Check if the filename can be processed by any of the registered methods.
Parameter: | filename (string) – filename |
---|
Get all methods registered for an extension.
Parameter: | extension (string) – file extension |
---|---|
Returns: | list of methods registered for the extension |
Return type: | list |
Register one method for multiple extensions. If the method is None, it will cancel the registration.
Parameters: |
|
---|
Unregister an extension from all methods.
Parameter: | extensions (list of strings) – list of file extensions |
---|
Unregister a method from all extensions.
Parameters: |
|
---|
It is important to call this method when finished with the temporary file.
Parameters: |
|
---|
Ensure a path exists, create all not existing paths.
It raises an OSError, if an invalid path is specified.
Parameter: | path (str) – the absolute folder path (not relative!) |
---|
Converts a filename to a title. It replaces dashes with spaces and converts every first character to uppercase.
Parameter: | filename (str) – an absolute or relative path |
---|---|
Returns: | titled version of the filename |
Return type: | bool |
>>> filename_to_title('~/highlight_mask.png')
'Highlight Mask'
Find command in text
Parameter: | text (string) – command line |
---|---|
Returns: | text |
Return type: | text |
>>> find_command('convert image.jpg image.jpg')
'convert'
>>> find_command('"/my apps/convert" image.jpg image.jpg')
'"/my apps/convert"'
>>> find_command('/my apps/convert image.jpg image.jpg')
'/my'
Finds an executable binary. Returns None if the binary can not be found.
This method need some extra love for Windows and Mac.
Parameters: |
|
---|---|
Returns: | absolute path to the binary |
Return type: | string or None |
>>> find_exe('python')
'/usr/bin/python'
>>> find_exe('python', use_which=False)
'/usr/bin/python'
Finds a filename in a list of paths.
Parameters: |
|
---|---|
Returns: | found filename with path or None |
Return type: | string or None |
Fix quotes for a command line parameter. Only surround by quotes if a space is present in the filename.
Parameter: | text (string) – command line parameter |
---|---|
Returns: | text with quotes if needed |
Return type: | string |
>>> fix_quotes('blender')
'blender'
>>> fix_quotes('/my programs/blender')
'"/my programs/blender"'
Checks wether a path is a valid local or remote file.
Parameter: | path (str) – the path which has to be checked |
---|---|
Returns: | True if path is a valid local or remote file, False otherwise |
Return type: | bool |
>>> is_file('http://www.foo.com/logo.png')
True
>>> is_file('ftp://foo.com/logo.png')
True
>>> is_file('/etc/fstab')
True
>>> is_file('/etc/fstap')
False
Checks whether a file is remote (http or ftp).
Parameter: | url (str) – file path or url |
---|---|
Returns: | True if remote, False if local |
Return type: | bool |
>>> is_www_file('http://www.foo.com/logo.png')
True
>>> is_www_file('ftp://foo.com/logo.png')
True
>>> is_www_file('logo.png')
False
Initializes where binaries can be found.
Parameter: | paths (list of strings) – list of paths where binaries might be found |
---|
Runs a shell command and captures the output.
Parameter: | args (tuple of strings) – the command to be executed in the shell |
---|---|
Returns: | stdout and stdout |
Return type: | typle of strings |
>>> shell('echo world', shell=True)
('world\n', '')
Runs a shell command and captures the output. It uses a caching system so that cached results don’t need to run a subprocess anymore. The results are cached by sys.platform
Parameters: |
|
---|---|
Returns: | stdout and stdout |
Return type: | typle of strings |
>>> shell('echo world', shell=True)
('world\n', '')
Runs a shell command and returns it’s exit code.
Parameter: | args (tuple of strings) – the command to be executed in the shell |
---|---|
Returns: | command exit code |
Return type: | integer |
Breaks a single command line into a list of string arguments.
Parameter: | text (str) – command line text |
---|---|
Returns: | list of arguments |
Return type: | list of str |
>>> split_command('blender file_in.png file_out.png')
['blender', 'file_in.png', 'file_out.png']
>>> split_command('"/my progs/blender" file_in.png file_out.png')
['"/my progs/blender"', 'file_in.png', 'file_out.png']
Open a file or browse a folder.
Parameter: | path (string) – location of the file |
---|
Turns a text in a title
Parameter: | text (str) – text |
---|---|
Returns: | title |
Return type: | str |
>>> title('hello_world')
'Hello World'