+ l = make_ldap_conn()
+
+ if options.generatedir is not None:
+ generate_dir = os.environ['UD_GENERATEDIR']
+ elif 'UD_GENERATEDIR' in os.environ:
+ generate_dir = os.environ['UD_GENERATEDIR']
+
+ ldap_last_mod = getLastLDAPChangeTime(l)
+ cache_last_mod = getLastBuildTime(generate_dir)
+ need_update = ldap_last_mod > cache_last_mod
+
+ if not options.force and not need_update:
+ fd = open(os.path.join(generate_dir, "last_update.trace"), "w")
+ fd.write("%s\n%s\n" % (ldap_last_mod, int(time.time())))
+ fd.close()
+ sys.exit(0)
+
+ lock = None
+ try:
+ lockf = os.path.join(generate_dir, 'ud-generate.lock')
+ lock = get_lock( lockf )
+ if lock is None:
+ sys.stderr.write("Could not acquire lock %s.\n"%(lockf))
+ sys.exit(1)
+
+ tracefd = open(os.path.join(generate_dir, "last_update.trace"), "w")
+ generate_all(generate_dir, l)
+ tracefd.write("%s\n%s\n" % (ldap_last_mod, int(time.time())))
+ tracefd.close()
+
+ finally:
+ if lock is not None:
+ lock.close()
+
+
+if __name__ == "__main__":
+ if 'UD_PROFILE' in os.environ:
+ import cProfile
+ import pstats
+ cProfile.run('ud_generate()', "udg_prof")
+ p = pstats.Stats('udg_prof')
+ ##p.sort_stats('time').print_stats()
+ p.sort_stats('cumulative').print_stats()
+ else:
+ ud_generate()