api — Phatch v0.2 documentation

### Navigation

- index
- modules |
- next |
- previous |
- Phatch v0.2 documentation »
- core »

# api

exception `core.api.` `PathError`(filename)
  Bases: `exceptions.Exception`

`core.api.` `apply_action_to_photo`(action, photo, read_only_settings, cache, image_file, result)

  Apply a single action to a photo. It uses `log_error()` for non fatal errors or `process_error()` for serious errors. The settings are read only as the actions don’t have permission to change them.

  Parameters: | action (`core.models.Action`) – action photo (`core.pil.Photo`) – photo read_only_settings (`lib.odict.ReadOnlyDict`) – read only settings cache (dictionary) – cache for data which is usefull across photos image_file (string) – filename reference during error logging result (dictionary) – settings for dialog (eg `stop_for_errors`)

`core.api.` `apply_actions_to_photo`(actions, image_info, info_not_file, cache, read_only_settings, skip_existing_images, result, report, is_done, image_index, repeat)
  Apply the action list to one photo.

`core.api.` `apply_actions_to_photos`(actions, settings, paths=None, drop=False, update=None)

  Apply all the actions to the photos in path.

  Parameters: | actions (list of `core.models.Action`) – actions settings (dictionary) – process settings (writable, eg recursion, ...) paths (list of strings) – paths where the images are located. If they are not specified, Phatch will ask them to the user. drop (bool) – True in case files were dropped or phatch is started as a droplet.

`core.api.` `assert_safe`(actions)

`core.api.` `check_actionlist`(actions, settings)

  Verifies action list before executing. It checks whether:

  - the action list is not empty
  - all actions are not disabled
  - if there is a save action at the end or only file actions
  - overwriting images is forced

  Parameters: | actions (list of `core.models.Action`) – actions of the action list settings (dictionary) – execution settings

      >>> settings = {'no_save':False}
      >>> check_actionlist([], settings) is None
      True
      >>> from actions import canvas, save
      >>> canvas_action = canvas.Action()
      >>> save_action = save.Action()
      >>> check_actionlist([canvas_action,save_action],
      ... {'no_save':False}) is None
      False
      >>> check_actionlist([canvas_action], settings) is None
      True
      >>> settings = {'no_save':True}
      >>> check_actionlist([canvas_action], settings) is None
      False
      >>> settings['overwrite_existing_images_forced']
      False

`core.api.` `check_actionlist_file_only`(actions)

  Check whether the action list only exist of file operations (such as copy, rename, ...)

  Parameter: | actions – actions of the action list
  Type: | list of `core.models.Action`
  Returns: | True if only file operations, False otherwise
  Return type: | bool

      >>> from actions import canvas, rename
      >>> check_actionlist_file_only([canvas.Action()])
      False
      >>> check_actionlist_file_only([rename.Action()])
      True

`core.api.` `filter_image_infos`(folder, extensions, files, root, info_file)

  Filter image files by extension and verify if they are files. It returns a list of info dictionaries which are generated by :method:`InfoPil.dump`:

      {'day': 14,
       'filename': 'beach',
       'filesize': 9682,
       'folder': u'/home/stani',
       'foldername': u'stani',
       'hour': 23,
       'minute': 43,
       'month': 3,
       'monthname': 'March',
       'path': '/home/stani/beach.jpg',
       'root': '/home',
       'second': 26,
       'subfolder': u'',
       'type': 'jpg',
       'weekday': 4,
       'weekdayname': 'Friday',
       'year': 2008,
       '$': 0}

  `$` is the index of the file within a folder.

  Helper function for `get_image_infos_from_folder()`

  Parameters: | folder (string) – folder path (recursion dependent) extensions (list of strings) – extensions (without `.`) files (list of strings) – list of filenames without folder path root (string) – root folder path (independent from recursion)
  Returns: | list of image file info
  Return type: | list of dictionaries

`core.api.` `flush_log`(photo, image_file, action=None)

  Flushes non fatal errors/warnings with `log_error()` and warnings that have been logged from the photo to the error log file.

  Parameters: | photo (class:core.pil.Photo) – photo which has photo.log image_file (string) – absolute path of the image action (`core.models.Action`) – action which was involved in the error (optional)

`core.api.` `get_image_infos`(paths, info_file, extensions, recursive)

  Get all image info dictionaries from a mix of folder and file paths.

  Parameters: | paths (list of strings) – file and/or folderpaths extensions (list of strings) – extensions (without `.`) recursive (bool) – include subfolders
  Returns: | list of image file info
  Return type: | list of dictionaries

`core.api.` `get_image_infos_from_folder`(folder, info_file, extensions, recursive)

  Get all image info dictionaries from a specific folder.

  Parameters: | folder (string) – top folder path extensions (list of strings) – extensions (without `.`) recursive (bool) – include subfolders
  Returns: | list of image file info
  Return type: | list of dictionaries

  Helper function for `get_image_infos()`

`core.api.` `get_paths_and_settings`(paths, settings, drop=False)

  Ask the user for paths and settings. In the GUI this shows the execute dialog box.

  Parameters: | paths (list of strings) – initial value of the paths (eg to fill in dialog) settings (dictionary) – settings drop (bool) – True in case files were dropped or phatch is started as a droplet.

`core.api.` `get_photo`(info_file, info_not_file, result)

  Get a `core.pil.Photo` instance from a file. If there is an error opening the file, func:process_error will be called.

  Parameters: | info_file (dictionary) – file information info_not_file (string) – image information not related to file result (dict) – settings to send to progress dialog box (such as `stop for errors`)
  Returns: | photo, result
  Return type: | tuple

`core.api.` `get_vars`(actions)

  Extract all used variables from actions.

  Parameter: | actions (list of dict) – list of actions

`core.api.` `import_actions`()
  Import all actions from the `ct.PHATCH_ACTIONS_PATH`.

`core.api.` `import_module`(module, folder=None)

  Import a module, mostly used for actions.

  Parameters: | module (string) – module/action name folder (string) – folder where the module is situated

`core.api.` `init`()
  Verify user paths and import all actions. This function should be called at the start.

`core.api.` `init_actions`(actions)

  Initializes all actions. Shows an error to the user if an action fails to initialize.

  Parameter: | actions (list of `core.models.Action`) – actions
  Returns: | False, if one action fails, True otherwise
  Return type: | bool

`core.api.` `init_error_log_file`()
  Reset ERROR_LOG_COUNTER and create the ERROR_LOG_FILE.

`core.api.` `log_error`(message, filename, action=None, label='Error')

  Writer error message to log file.

  Helper function for `flush_log()`, `process_error()`.

  Parameters: | message (string) – error message filename (string) – image filename label (string) – `'Error'` or `'Warning'`
  Returns: | error log details
  Return type: | string

`core.api.` `open_actionlist`(filename)

  Open the action list from a file.

  Parameter: | filename (string) – the filename of the action list
  Returns: | action list
  Return type: | dictionary

`core.api.` `process_error`(photo, message, image_file, action, result, ignore)

  Logs error to file with `log_error()` and show dialog box allowing the user to skip, abort or ignore.

  Helper function for `get_photo()` and apply_action.

  Parameters: | photo (class:core.pil.Photo) – photo message (string) – error message image_file (string) – absolute path of the image result (dictionary) – settings for dialog (eg `stop_for_errors`)
  Returns: | photo, result
  Return type: | tuple

`core.api.` `save_actionlist`(filename, data)

  Save actionlist `data` to `filename`.

  Parameters: | filename (string) – filename of the actionlist, if it has no extension `.phatch` will be added automatically. data (dictionary) – action list data

  Actionlists are stored as dictionaries:

      data = {'actions':[...], 'description':'...'}

`core.api.` `verify_images`(image_infos, repeat)

  Filter invalid images out.

  Verify if images are not corrupt. Show the invalid images to the user. If no valid images are found, show an error to the user. Otherwise show the valid images to the user.

  Parameter: | image_infos (list of dictionaries) – list of image info dictionaries
  Returns: | None for error, valid image info dictionaries otherwise

### Navigation

- index
- modules |
- next |
- previous |
- Phatch v0.2 documentation »
- core »