+ return int(krmod)
+
+def getLastBuildTime(gdir):
+ cache_last_ldap_mod = 0
+ cache_last_unix_mod = 0
+ cache_last_run = 0
+
+ try:
+ fd = open(os.path.join(gdir, "last_update.trace"), "r")
+ cache_last_mod=fd.read().split()
+ try:
+ cache_last_ldap_mod = cache_last_mod[0]
+ cache_last_unix_mod = int(cache_last_mod[1])
+ cache_last_run = int(cache_last_mod[2])
+ except IndexError, ValueError:
+ pass
+ fd.close()
+ except IOError, e:
+ if e.errno == errno.ENOENT:
+ pass
+ else:
+ raise e
+
+ return (cache_last_ldap_mod, cache_last_unix_mod, cache_last_run)
+
+def mq_notify(options, message):
+ options.section = 'dsa-udgenerate'
+ options.config = '/etc/dsa/pubsub.conf'
+
+ config = Config(options)
+ 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
+ }
+
+ msg = {
+ 'message': message,
+ 'timestamp': int(time.time())
+ }
+ conn = None
+ try:
+ conn = Connection(conf=conf)
+ conn.topic_send(config.topic,
+ json.dumps(msg),
+ exchange_name=config.exchange,
+ timeout=5)
+ finally:
+ if conn:
+ conn.close()
+
+def ud_generate():
+ parser = optparse.OptionParser()
+ parser.add_option("-g", "--generatedir", dest="generatedir", metavar="DIR",
+ help="Output directory.")
+ parser.add_option("-f", "--force", dest="force", action="store_true",
+ help="Force generation, even if no update to LDAP has happened.")
+
+ (options, args) = parser.parse_args()
+ if len(args) > 0:
+ parser.print_help()
+ sys.exit(1)
+
+ if options.generatedir is not None:
+ generate_dir = os.environ['UD_GENERATEDIR']
+ elif 'UD_GENERATEDIR' in os.environ:
+ generate_dir = os.environ['UD_GENERATEDIR']