Skip to content
Snippets Groups Projects
Commit c699b0de authored by Daniele Nicolodi's avatar Daniele Nicolodi
Browse files

bestellanforderung: Add sketch for a sync command

parent 1d610c49
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import toml
import zipfile
import openpyxl
from itertools import groupby
from os import path
from xml.etree import ElementTree
......@@ -219,5 +220,49 @@ def extract(conf, verbose):
printer.print_entries(entries)
@main.command()
@click.pass_obj
def sync(conf):
"""Sync order request forms to central repository."""
fromdate = datetime.date(2021, 11, 1)
datadir = path.realpath(conf['documents'])
destdir = r'O:\4-3\4-3-Alle\Organisation\Beschaffungen\2021\4.31\Nicolodi'
click.echo(f'{destdir}{os.sep}')
updated = []
for entry in os.listdir(datadir):
src = path.join(datadir, entry)
dst = path.join(destdir, entry)
if not path.isdir(src):
continue
m = re.match(r'(\d{8})__(.+)$', entry)
if not m:
continue
date = datetime.datetime.strptime(m.group(1), '%Y%m%d').date()
if date < fromdate:
continue
srcmap = {entry.name: entry.stat().st_mtime for entry in os.scandir(src) if not entry.name.startswith('~')}
dstmap = {entry.name: entry.stat().st_mtime for entry in os.scandir(dst) if not entry.name.startswith('~')}
for name, mtime in srcmap.items():
if mtime > dstmap.get(name, 0):
updated.append((entry, '>', name))
for name, mtime in dstmap.items():
if mtime > srcmap.get(name, 0):
updated.append((entry, '<', name))
for folder, entries in groupby(updated, key=lambda x: x[0]):
click.echo(f'· {folder}{os.sep}')
for entry in entries:
note = click.style(entry[1], fg='red' if entry[1] == '<' else 'green')
click.echo(f' {note} {entry[2]}')
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment