Various Improvements and Changes #1

Open
june wants to merge 9 commits from june/hedgedoc-expire:patches into main
Showing only changes of commit 62cd667db5 - Show all commits

View file

@ -26,6 +26,7 @@ class Config:
self.verbose = False
self.revision_age = timedelta(days=14)
self.note_age = timedelta(days=95)
self.exclude = []
self.postgres_hostname = getenv('POSTGRES_HOSTNAME', 'localhost')
self.postgres_username = getenv('POSTGRES_USERNAME', 'hedgedoc')
@ -262,13 +263,30 @@ class HedgedocExpire:
def cmd_check(self) -> None:
with pgsql.Connection((self.config.postgres_hostname, self.config.postgres_port),
self.config.postgres_username, self.config.postgres_password) as db:
print(self.check_revisions_to_be_expired(db) +
self.check_notes_to_be_expired(db))
if 'revision' not in self.config.exclude:
print(self.check_revisions_to_be_expired(db))
elif self.config.verbose:
print("Revisions were excluded from check, not checking.\n")
if 'note' not in self.config.exclude:
print(self.check_notes_to_be_expired(db))
elif self.config.verbose:
print("Notes were excluded from check, not checking.\n")
def cmd_emailcheck(self) -> None:
with pgsql.Connection((self.config.postgres_hostname, self.config.postgres_port),
self.config.postgres_username, self.config.postgres_password) as db:
report = self.check_revisions_to_be_expired(db) + self.check_notes_to_be_expired(db)
report = ''
if 'revision' not in self.config.exclude:
report += self.check_revisions_to_be_expired(db)
else:
report += "Revisions were excluded from check.\n"
if 'note' not in self.config.exclude:
report += self.check_notes_to_be_expired(db)
else:
report += "Notes were excluded from check.\n"
msg = MIMEMultipart()
msg['From'] = self.email_sender.mail_from
msg['To'] = self.email_sender.mail_from
@ -285,8 +303,15 @@ class HedgedocExpire:
def cmd_expire(self) -> None:
with pgsql.Connection((self.config.postgres_hostname, self.config.postgres_port),
self.config.postgres_username, self.config.postgres_password) as db:
if 'revision' not in self.config.exclude:
self.expire_old_revisions(db)
elif self.config.verbose:
print("Revisions were excluded from action, not expiring.\n")
if 'note' not in self.config.exclude:
self.expire_old_notes(db)
elif self.config.verbose:
print("Notes were excluded from action, not expiring.\n")
def main():
@ -317,12 +342,17 @@ def main():
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.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)