mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
remove superflous Stats class
This commit is contained in:
@@ -17,18 +17,10 @@ from chatmaild.config import read_config
|
||||
FileEntry = namedtuple("FileEntry", ("relpath", "mtime", "size"))
|
||||
|
||||
|
||||
class Stats:
|
||||
def __init__(self, basedir, maxnum=None):
|
||||
self.basedir = str(basedir)
|
||||
self.maxnum = maxnum
|
||||
|
||||
def iter_mailboxes(self, callback=None):
|
||||
for name in os.listdir(self.basedir)[: self.maxnum]:
|
||||
if "@" in name:
|
||||
basedir = self.basedir + "/" + name
|
||||
mailbox = MailboxStat(basedir)
|
||||
if callback is not None:
|
||||
callback(mailbox)
|
||||
def iter_mailboxes(basedir, maxnum):
|
||||
for name in os.listdir(basedir)[:maxnum]:
|
||||
if "@" in name:
|
||||
yield MailboxStat(basedir + "/" + name)
|
||||
|
||||
|
||||
class MailboxStat:
|
||||
@@ -69,9 +61,8 @@ def print_info(msg):
|
||||
|
||||
|
||||
class Expiry:
|
||||
def __init__(self, config, stats, dry, now, verbose):
|
||||
def __init__(self, config, dry, now, verbose):
|
||||
self.config = config
|
||||
self.stats = stats
|
||||
self.dry = dry
|
||||
self.now = now
|
||||
self.verbose = verbose
|
||||
@@ -173,9 +164,9 @@ def main(args):
|
||||
now = now - 86400 * int(args.days)
|
||||
|
||||
maxnum = int(args.maxnum) if args.maxnum else None
|
||||
stats = Stats(os.path.abspath(args.mailboxes_dir), maxnum=maxnum)
|
||||
exp = Expiry(config, stats, dry=not args.remove, now=now, verbose=args.verbose)
|
||||
stats.iter_mailboxes(exp.process_mailbox_stat)
|
||||
exp = Expiry(config, dry=not args.remove, now=now, verbose=args.verbose)
|
||||
for mailbox in iter_mailboxes(os.path.abspath(args.mailboxes_dir), maxnum=maxnum):
|
||||
exp.process_mailbox_stat(mailbox)
|
||||
print(exp.get_summary())
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
from argparse import ArgumentParser
|
||||
from datetime import datetime
|
||||
|
||||
from chatmaild.expire import Stats
|
||||
from chatmaild.expire import iter_mailboxes
|
||||
|
||||
DAYSECONDS = 24 * 60 * 60
|
||||
MONTHSECONDS = DAYSECONDS * 30
|
||||
@@ -35,14 +35,13 @@ def H(size):
|
||||
|
||||
|
||||
class Report:
|
||||
def __init__(self, stats, now):
|
||||
def __init__(self, now):
|
||||
self.sum_extra = 0
|
||||
self.sum_all_messages = 0
|
||||
self.messages = []
|
||||
self.mailboxes = []
|
||||
self.user_logins = []
|
||||
self.ci_logins = []
|
||||
self.stats = stats
|
||||
self.now = now
|
||||
|
||||
def process_mailbox_stat(self, mailbox):
|
||||
@@ -154,9 +153,9 @@ def main(args=None):
|
||||
now = now - 86400 * int(args.days)
|
||||
|
||||
maxnum = int(args.maxnum) if args.maxnum else None
|
||||
stats = Stats(args.mailboxes_dir, maxnum=maxnum)
|
||||
rep = Report(stats, now=now)
|
||||
stats.iter_mailboxes(rep.process_mailbox_stat)
|
||||
rep = Report(now=now)
|
||||
for mbox in iter_mailboxes(os.path.abspath(args.mailboxes_dir), maxnum=maxnum):
|
||||
rep.process_mailbox_stat(mbox)
|
||||
rep.dump_summary()
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import pytest
|
||||
|
||||
from chatmaild.expire import FileEntry, MailboxStat
|
||||
from chatmaild.expire import main as expiry_main
|
||||
from chatmaild.fsreport import Report, Stats
|
||||
from chatmaild.fsreport import Report, iter_mailboxes
|
||||
|
||||
# XXX basedirsize (used by dovecot quota) needs to be removed after removing files
|
||||
|
||||
@@ -58,7 +58,7 @@ def test_stats_mailbox(mbox1):
|
||||
assert mbox1.last_login == password.stat().st_mtime
|
||||
assert len(mbox1.messages) == 2
|
||||
|
||||
msgs = list(mbox1.messages)
|
||||
msgs = list(sorted(mbox1.messages, key=lambda x: x.size))
|
||||
assert len(msgs) == 2
|
||||
assert msgs[0].size == 500 # cur
|
||||
assert msgs[1].size == 600 # new
|
||||
@@ -78,9 +78,9 @@ def test_stats_mailbox(mbox1):
|
||||
def test_report(mbox1):
|
||||
now = datetime.utcnow().timestamp()
|
||||
mailboxes_dir = Path(mbox1.basedir).parent
|
||||
stats = Stats(str(mailboxes_dir), maxnum=None)
|
||||
rep = Report(stats, now=now)
|
||||
stats.iter_mailboxes(rep.process_mailbox_stat)
|
||||
rep = Report(now=now)
|
||||
for mailbox in iter_mailboxes(str(mailboxes_dir), maxnum=None):
|
||||
rep.process_mailbox_stat(mailbox)
|
||||
rep.dump_summary()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user