1
0
Fork 0
Commit graph

4 commits

Author SHA1 Message Date
Florent Rougon
8009f46a51 terrasync.py: improve code readability 2020-10-03 14:55:25 +02:00
Florent Rougon
692ab6835f terrasync.py: more thorough checking of .dirindex contents
- only accept ASCII-encoded .dirindex files (this is guaranteed to work
  fine "everywhere");

- reject .dirindex files with a 'path' entry that contains a backslash
  or starts with a slash;

- reject .dirindex files with a 'path' entry that contains a '..'
  component;

- reject .dirindex files with an 'f', 'd' or 't' entry whose name field
  contains a slash or a backslash;

- reject .dirindex files with an 'f', 'd' or 't' entry whose name field
  is '..';

- add comment lines (starting with '#') in the sample good .dirindex
  file used by unit tests.
2020-10-03 14:18:29 +02:00
Florent Rougon
13f943b4a1 terrasync.py: rename DirIndex attributes and remove accessors
In Python, common usage is not to define accessors, but to directly use
class or instance attributes (especially when the associated data is
constant after instance creation). If it later happens that a given
attribute needs getter or setter logic, this can always be done via the
@property decorator, and doesn't affect calling code at all. See for
instance:

  https://docs.python.org/3/library/functions.html#property
  https://mail.python.org/pipermail/tutor/2012-December/thread.html#92990

Apply this to the DirIndex class and rename the following attributes for
better readability: f -> files, d -> directories, t -> tarballs.
2020-10-02 16:38:08 +02:00
Florent Rougon
477d9f7a9a terrasync.py: move the DirIndex class to its own module and add unit tests
The tests can be run from directory 'scripts/python/TerraSync' using:

  python3 -m unittest tests.test_dirindex

(or just 'python3 -m unittest' to run all tests pertaining to
terrasync.py).
2020-10-02 16:38:08 +02:00