# THE SOFTWARE.
from collections import defaultdict
+from dsa_mq.connection import Connection
+from dsa_mq.config import Config
import email
import email.mime.text
import glob
import logging
+from optparse import OptionParser
import os.path
import platform
import pwd
+import socket
import subprocess
import struct
import time
# avoid base64 encoding for utf-8
email.charset.add_charset('utf-8', email.charset.SHORTEST, email.charset.QP)
-DRYRUN = False
-
-if DRYRUN:
+parser = OptionParser()
+parser.add_option("-D", "--dryrun",
+ action="store_true", default=False,
+ help="Dry run mode")
+
+parser.add_option("-d", "--debug",
+ action="store_true", default=False,
+ help="Enable debug output")
+
+(options, args) = parser.parse_args()
+options.section = 'dsa-homedirs'
+options.config = '/etc/dsa/pubsub.conf'
+config = Config(options)
+mq_conf = {
+ 'rabbit_userid': config.username,
+ 'rabbit_password': config.password,
+ 'rabbit_virtual_host': config.vhost,
+ 'rabbit_hosts': ['pubsub02.debian.org', 'pubsub01.debian.org'],
+ 'use_ssl': False
+}
+
+if options.dryrun:
SENDMAIL_COMMAND = ['/bin/cat']
RM_COMMAND = ['/bin/echo', 'Would remove']
else:
def run(self):
current_time = time.time()
+ try:
+ msg = {
+ 'timestamp': current_time,
+ 'data': self.homedir_sizes,
+ 'host': socket.gethostname()
+ }
+ conn = Connection(conf=mq_conf)
+ conn.topic_send(config.topic,
+ msg,
+ exchange_name=config.exchange,
+ timeout=5)
+ except Exception, e:
+ LOG.error("Error sending: %s" % e)
+ finally:
+ if conn:
+ conn.close()
for username, homedir_size in self.homedir_sizes.iteritems():
try:
self.notify(**kwargs)
if __name__ == '__main__':
- logging.basicConfig()
- # DEBUG for debugging, ERROR for production.
- logging.getLogger().setLevel(logging.ERROR)
+ lvl = logging.ERROR
+ if options.debug:
+ lvl = logging.DEBUG
+ logging.basicConfig(level=lvl)
HomedirReminder().run()