forked from CCCHH/hedgedoc-expire
remove the exclude arg and instead have the revs and notes args be opt.
And then only act on notes/revisions, if the relevant argument got specified. This makes the CLI cleaner.
This commit is contained in:
parent
4bee60b8dd
commit
07ef29225e
2 changed files with 36 additions and 26 deletions
24
README.md
24
README.md
|
@ -12,12 +12,16 @@ Currently, it only works with Postgres.
|
|||
|
||||
### Expiring old revisions
|
||||
|
||||
Using the `-r` or `--revisions` argument.
|
||||
|
||||
All revisions that have been created before the specified age will be removed. If all revisions are expired, the note
|
||||
remains available, it just won't have any revisions to revert to. Once you continue editing it, new revisions will be
|
||||
added.
|
||||
|
||||
### Expiring old notes
|
||||
|
||||
Using the `-n` or `--notes` argument.
|
||||
|
||||
Notes that are being expired will be emailed to the account that initially created the note. This allows that user to
|
||||
restore the note, if necessary. Expiring a note will also remove all existing revisions for the note.
|
||||
|
||||
|
@ -28,10 +32,22 @@ be recovered.
|
|||
|
||||
## Running `hedgedoc-expire.py`
|
||||
|
||||
Locally from the command line:
|
||||
Locally from the command line expiring revisions and notes older than 7 days:
|
||||
|
||||
```shell
|
||||
poetry run python ./hedgedoc-expire.py ...
|
||||
poetry run python ./hedgedoc-expire.py expire -n 7 -r 7
|
||||
```
|
||||
|
||||
Locally from the command line only expiring revisions older than 7 days:
|
||||
|
||||
```shell
|
||||
poetry run python ./hedgedoc-expire.py expire -r 7
|
||||
```
|
||||
|
||||
Locally from the command line only expiring notes older than 7 days:
|
||||
|
||||
```shell
|
||||
poetry run python ./hedgedoc-expire.py expire -n 7
|
||||
```
|
||||
|
||||
From Docker Compose:
|
||||
|
@ -65,8 +81,8 @@ Without it, the expiry action will be taken.
|
|||
|
||||
| Option | Default | Description |
|
||||
|--------|---------|-------------------------------------------------------------------|
|
||||
| -n | 90 | remove all notes not changed in these many days |
|
||||
| -r | 7 | remove all revisions created more than these many days ago |
|
||||
| -n | None | remove all notes not changed in these many days |
|
||||
| -r | None | remove all revisions created more than these many days ago |
|
||||
| -v | false | Print info on current action during `cron` and `expire` commandds |
|
||||
|
||||
Command is one of:
|
||||
|
|
|
@ -29,7 +29,6 @@ class Config:
|
|||
self.verbose = False
|
||||
self.revision_age = timedelta(days=14)
|
||||
self.note_age = timedelta(days=95)
|
||||
self.exclude = []
|
||||
|
||||
self.postgres_connection_string = getenv('POSTGRES_CONNSTRING', 'postgresql://hedgedoc:geheim@localhost:5432/hedgedoc')
|
||||
|
||||
|
@ -276,29 +275,29 @@ class HedgedocExpire:
|
|||
|
||||
def cmd_check(self) -> None:
|
||||
with psycopg.connect(self.config.postgres_connection_string) as conn:
|
||||
if 'revision' not in self.config.exclude:
|
||||
if self.config.revision_age is not None:
|
||||
print(self.check_revisions_to_be_expired(conn))
|
||||
elif self.config.verbose:
|
||||
print("Revisions were excluded from check, not checking.\n")
|
||||
print("Revisions weren't included in the check, not checking.\n")
|
||||
|
||||
if 'note' not in self.config.exclude:
|
||||
if self.config.note_age is not None:
|
||||
print(self.check_notes_to_be_expired(conn))
|
||||
elif self.config.verbose:
|
||||
print("Notes were excluded from check, not checking.\n")
|
||||
print("Notes weren't included in the check, not checking.\n")
|
||||
|
||||
def cmd_emailcheck(self) -> None:
|
||||
with psycopg.connect(self.config.postgres_connection_string) as conn:
|
||||
report = ''
|
||||
|
||||
if 'revision' not in self.config.exclude:
|
||||
if self.config.revision_age is not None:
|
||||
report += self.check_revisions_to_be_expired(conn)
|
||||
else:
|
||||
report += "Revisions were excluded from check.\n"
|
||||
report += "Revisions weren't included in the check.\n"
|
||||
|
||||
if 'note' not in self.config.exclude:
|
||||
if self.config.note_age is not None:
|
||||
report += self.check_notes_to_be_expired(conn)
|
||||
else:
|
||||
report += "Notes were excluded from check.\n"
|
||||
report += "Notes weren't included in the check.\n"
|
||||
msg = MIMEMultipart()
|
||||
msg['From'] = self.email_sender.mail_from
|
||||
msg['To'] = self.email_sender.mail_from
|
||||
|
@ -315,15 +314,15 @@ class HedgedocExpire:
|
|||
|
||||
def cmd_expire(self) -> None:
|
||||
with psycopg.connect(self.config.postgres_connection_string) as conn:
|
||||
if 'revision' not in self.config.exclude:
|
||||
if self.config.revision_age is not None:
|
||||
self.expire_old_revisions(conn)
|
||||
elif self.config.verbose:
|
||||
print("Revisions were excluded from action, not expiring.\n")
|
||||
print("Revisions weren't included in the expire action, not expiring.\n")
|
||||
|
||||
if 'note' not in self.config.exclude:
|
||||
if self.config.note_age is not None:
|
||||
self.expire_old_notes(conn)
|
||||
elif self.config.verbose:
|
||||
print("Notes were excluded from action, not expiring.\n")
|
||||
print("Notes weren't included in the expire action, not expiring.\n")
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -346,25 +345,20 @@ def main():
|
|||
See https://git.hamburg.ccc.de/CCCHH/hedgedoc-expire
|
||||
''')
|
||||
)
|
||||
parser.add_argument('-n', '--notes', metavar='DAYS', type=float, default=95,
|
||||
parser.add_argument('-n', '--notes', metavar='DAYS', type=float,
|
||||
help='remove all notes not changed in these many days')
|
||||
parser.add_argument('-r', '--revisions', metavar='DAYS', type=float, default=14,
|
||||
parser.add_argument('-r', '--revisions', metavar='DAYS', type=float,
|
||||
help='remove all revisions created more than these many days ago')
|
||||
parser.add_argument('command', choices=['check', 'cron', 'emailcheck', 'expire'], default='check', nargs='?',
|
||||
help='action to perform')
|
||||
parser.add_argument('-v', '--verbose', action='store_true', default=False,
|
||||
help='print more info while running')
|
||||
parser.add_argument('--exclude', nargs="+", choices=['revision', 'note'],
|
||||
help='Type ("revision" or "note") to exclude from the action.')
|
||||
args = parser.parse_args()
|
||||
|
||||
config = Config()
|
||||
config.note_age = timedelta(days=args.notes)
|
||||
config.revision_age = timedelta(days=args.revisions)
|
||||
config.note_age = timedelta(days=args.notes) if args.notes is not None else None
|
||||
config.revision_age = timedelta(days=args.revisions) if args.revisions is not None else None
|
||||
config.verbose = args.verbose
|
||||
if (args.exclude):
|
||||
config.exclude = args.exclude
|
||||
print(config.exclude)
|
||||
mail = EmailSender(config.smtp_hostname, config.smtp_port, config.smtp_username, config.smtp_password,
|
||||
config.smtp_from)
|
||||
hedgedoc_expire = HedgedocExpire(config, mail)
|
||||
|
|
Loading…
Reference in a new issue