Skip to content
Chris edited this page Oct 1, 2017 · 3 revisions

Specifying Filetypes (filetypes.yaml)

Making your own custom rules is the extensibility that makes pysorter so useful. Coming up with a rigorous specification for filetypes definitions is of great importance.

A proposed specification by example:

---
config:
  # mimetypes etc added in rules.py
  # TODO: clarify necessity of config header
  version: 1

# Below we show various styles for defining 
rules:
  prefix: 'organized/'
  archives:
    gpri: 0
    dst: 'archives/'
    patterns:
      - ['\.(?i)gz$', '\.(?i)ace$', '\.(?i)ace$', '\.(?i)zip$', '\.(?i)tar$', '\.(?i)rar$', '\.(?i)7z$', '\.(?i)bz2$']
      - pat: '\.(?i)cab$'
        dst: 'cab/'
      - pat: '\.(?i)jar$'
        dst: 'jar/'
      - pat: '\.(?i)iso$'
        dst: 'iso/'
    skips:
      - '\.arj$'
      - '\.sz$'
  projects:
    gpri: 0
    dst: 'projects/'
    patterns:
      - - '\.(?i)aup$'
        - 'audacity_projects/'
      - - '\.(?i)bwg$'
        - 'brain_wave_generator_projects/'
      - - '\.(?i)sbk$'
        - 'scrapbook_factory/'
      - - '\.(?i)cdr$'
        - 'corel/'
    skips: ['\.idea$','\.git.*']
  contacts:
    patterns:
      - pat: '\.(?i)vcf$'
        dst: 'contacts/'
  # singular rule, .e. no group
  certs:
    pat: '\.(?i)cer$'
    dst: 'certificates/'
  # global skip definition
  skips: ['\.yaml$', '\.idea$', '\.pyc$', '\.mid[i|di]$']

Breaking down this example we find the following directives:

config:

this is a reserved area for configuration parameters

rules:

this is where filetype rules are specified

prefix:

for all filetypes, literally prepend this prefix to all destination paths

[rule_name]:

all named items in the rules section that are not prefix (or skips, see below) are rules.

gpri:

this is the priority for the group. sets precedent for conflicting rules.

dst:

this is the group destination prefix, at this point we have {prefix}/{dst}/ for the current group destination

patterns:

this keyword indicates that we are in a group, i.e. there will be multiple pattern/dest pairs. This is what the parser looks for to determine if an item is a group.

The list with no key name is the patterns that are matched to the group destination. The other pat/dst pairs inherit the group destination (i.e. {prefix}/{dst}/)

skips

the skipped filetypes the group carries. These will be of issue when handling priorities, as skipped patterns will need to be cross-referenced with patterns indicated in rules, and the priorities reconciled.

singular rule (non-group)

the 'certs' rule in this example is a 'singular rule', it only has pat/dst indicated. Priorities can be added to singular rules (point for discussion).

skips

any miscellaneous skips for this filetypes.yaml, they extend all skips specified in groups.