-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck.py
More file actions
executable file
·75 lines (64 loc) · 2.55 KB
/
check.py
File metadata and controls
executable file
·75 lines (64 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
#------------------------------------------------------------------------------
# direncrypt - Sync contents between encrypted and decrypted directories
# Copyright (C) 2015 Domagoj Marsic
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contact:
# https://github.com/dmarsic
# <dmars+github@protonmail.com>
#------------------------------------------------------------------------------
"""Check existence of files in unencrypted and encrypted directory
based on the register list. Register is a schema in inventory.sqlite
that contains mapping between encrypted and unencrypted files.
Reports discrepancies unless switch is specified to clean up.
"""
import os
import argparse
import getpass
from direncrypt import DATABASE
from direncrypt.consistency import ConsistencyCheck
if __name__ == "__main__":
database = DATABASE
parser = argparse.ArgumentParser(
'Check/fix consistency between unencrypted and encrypted files')
group = parser.add_mutually_exclusive_group()
group.add_argument('-c', '--clean',
action='store_true',
help='File does not exist, delete entry from register')
group.add_argument('-r', '--resync',
action='store_true',
help='Effectively decrypt existing encrypted file to plaindir')
group.add_argument('-d', '--delete',
action='store_true',
help='Delete orphans encoded files (which are not in register)')
group.add_argument('-l', '--list',
action='store_true',
help='Displays number of records')
args = parser.parse_args()
c = ConsistencyCheck(database)
c.check()
if args.clean:
c.loop_through(clean=True)
elif args.delete:
c.delete_orphans_encrypted_files()
elif args.list:
c.list_records()
elif args.resync:
passphrase = getpass.getpass('Passphrase: ')
c.set_passphrase(passphrase)
c.loop_through(resync=True)
else:
c.loop_through()