### Navigation

- index
- modules |
- next |
- previous |
- Phatch 0.2 documentation »
- lib »

# system

class `lib.system.``MethodRegister`
  `does_process`(filename)

    Check if the filename can be processed by any of the registered methods.

    Parameters: | filename (string) – filename

  `get_methods`(extension)

    Get all methods registered for an extension.

    Parameters: | extension (string) – file extension
    Returns: | list of methods registered for the extension
    Return type: | list

  `register`(extensions, method)

    Register one method for multiple extensions. If the method is None, it will cancel the registration.

    Parameters:

    - extensions (list of strings) – list of file extensions
    - method – method to open a file
    - method – function

  `unregister_extension`(extension)

    Unregister an extension from all methods.

    Parameters: | extensions (list of strings) – list of file extensions

  `unregister_method`(method)

    Unregister a method from all extensions.

    Parameters:

    - method – method to open a file
    - method – function

class `lib.system.``TempFile`(suffix='', path=None)
  `close`(force_remove=True, dest='')

    It is important to call this method when finished with the temporary file.

    Parameters:

    - force_remove (boolean) – Remove temporary file and raise IOError when it does not exist anymore. Set to False too allow for processes that delete the temporary file when failing to exit succesfully.
    - dest (string) – This is eg used for thumbnails in order to rename them to their proper location

`lib.system.``call`(args, **keyw)

  Same as subprocess.call, but if only a command line text is given it breaks it in a list of arguments so it can be used also with `shell=False` on Unix.

`lib.system.``ensure_path`(path)

  Ensure a path exists, create all not existing paths.

  It raises an OSError, if an invalid path is specified.

  Parameters: | path (str) – the absolute folder path (not relative!)

`lib.system.``file_extension`(uri)

`lib.system.``filename_to_title`(filename)

  Converts a filename to a title. It replaces dashes with spaces and converts every first character to uppercase.

  Parameters: | filename (str) – an absolute or relative path
  Returns: | titled version of the filename
  Return type: | bool

      >>> filename_to_title('~/highlight_mask.png')
      'Highlight Mask'

`lib.system.``find_command`(text)

  Find command in text

  Parameters: | 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'

`lib.system.``find_exe`(executable, quote=True, use_which=True, raise_exception=False)

  Finds an executable binary. Returns None if the binary can not be found.

  This method need some extra love for Windows and Mac.

  Parameters:

  - executable (string) – binary which will be used as a plugin (eg imagemagick)
  - quote (bool) – quote the path if it contains spaces
  - use_which (bool) – use the command `which` on non windows platforms
  - raise_exception (bool) – raise exception if not found

  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'

`lib.system.``find_in`(filename, paths)

  Finds a filename in a list of paths.

  Parameters:

  - filename (str) – filename
  - paths (list of strings) – paths

  Returns: | found filename with path or None
  Return type: | string or None

`lib.system.``fix_quotes`(text)

  Fix quotes for a command line parameter. Only surround by quotes if a space is present in the filename.

  Parameters: | 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"'

`lib.system.``is_file`(path)

  Checks wether a path is a valid local or remote file.

  Parameters: | 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

`lib.system.``is_www_file`(url)

  Checks whether a file is remote (http or ftp).

  Parameters: | 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

`lib.system.``set_bin_paths`(paths=[])

  Initializes where binaries can be found.

  Parameters: | paths (list of strings) – list of paths where binaries might be found

`lib.system.``shell`(*args, **options)

  Runs a shell command and captures the output.

  Parameters: | 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', '')

`lib.system.``shell_cache`(args, cache='', key=None, validate=None, **options)

  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:

  - args (tuple of strings) – the command to be executed in the shell
  - cache (string) – the filename of the cache file
  - validate – a validate (eg mtime) to validate the cache result

  Returns: | stdout and stdout
  Return type: | typle of strings

      >>> shell('echo world', shell=True)
      ('world\n', '')

`lib.system.``shell_returncode`(*args, **options)

  Runs a shell command and returns it’s exit code.

  Parameters: | args (tuple of strings) – the command to be executed in the shell
  Returns: | command exit code
  Return type: | integer

`lib.system.``split_command`(text)

  Breaks a single command line into a list of string arguments.

  Parameters: | 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']

`lib.system.``start`(path)

  Open a file or browse a folder.

  Parameters: | path (string) – location of the file

`lib.system.``title`(text)

  Turns a text in a title

  Parameters: | text (str) – text
  Returns: | title
  Return type: | str

      >>> title('hello_world')
      'Hello World'

`lib.system.``wrap`(text, fill=70)

### Navigation

- index
- modules |
- next |
- previous |
- Phatch 0.2 documentation »
- lib »