hackerbase/doc/formats.md

3.6 KiB

File Formats

This file documents the internal structure of various file formats used. Currently the basic format is used for members files and global configuration.

Members Directory

Files in this directory with file names being four decimal digits are member files. The file name is the member id.

Symlinks to the member files serve as human-readable aliases.

The implementation handles situation when the human-readable name is the member file and the symlink is the four-digit member id.

Key File Parsing - Passes 0 and 1

All files are read line-by-line. This applies to both member file and configuration file.

Pass 0

Comments start with the # character and continue until the end of particular line.

Comments are stripped from each line before parsing. The same applies to leading and trailing whitespace after stripping comments.

Pass 1

Lines are processed as they are returned from pass 0.

Empty lines are skipped.

Lines without any whitespace are interned as symbols and error is recorded as there is only the key and no value associated with it.

Each key/value pair must begin with key token composed of non-whitespace characters before the first whitespace. This token is interned as symbol upon parsing the line. The remainder of the line is stripped of leading whitespace and stored as a string representing the value for the key.

The result of parsing is a list of parsed records containing key, value and line number for further processing.

Member File Processing - Pass 2

Processed source is scanned for known keys. Known keys are:

  • nick
  • name
  • mail
  • phone
  • born

Multiple instances of single key are considered an error.

Unknown keys are considered a warning.

Valid multikeys are converted to single key with list of values and line numbers as the value for such key. Multikeys are:

  • joined
  • destroyed
  • card
  • desfire
  • credit
  • studentstart
  • studentstop
  • suspendstart
  • suspendstop
  • chairstart
  • chairstop
  • councilstart
  • councilstop
  • revisionstart
  • revisionstop
  • grantstart
  • grantstop

The result is a valid dictionary of keys and multikeys.

Member File Interpreter - Passes 3+

After getting a valid dictionary from the 2nd pass, the data gets interpreted.

Pass Markers

All start/stop markers are joined into lists of markers, retaining source position information.

Info

The student and suspend lists of markers are converted into a lists of periods.

The joined key is converted into a month value.

Card and desfire lists are parsed to get lists of card id and optional comment.

Credit list is parsed to get a list of amounts and optional comments.

Member Record Finalization

If there is no 'joined key, default month is substituted.

If any of Mandatory keys is missing, it is filled with #f. Mandatory keys are:

  • nick
  • name
  • mail
  • phone

Configuration File Parsing - Pass 2

Basic passes 0 and 1 are performed and then only the following keys are used to set initial values for runtime parameters:

  • members-directory
  • apikeys-file
  • checked-file
  • bank-dir
  • email-from
  • summary-mailto
  • dokuwiki

API Keys File

Each line represents one Fio account.

There must be no leading whitespace on any line. No comments or empty lines are allowed.

Tokens on a line are separated by spaces.

Currently each line must have at least three tokens and only these three tokens are used:

  • account number
  • Fio API key
  • starting year since when this account is synchronized