7 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
8 sys.path.append("/opt/planetstack")
9 from planetstack.config import Config
10 from util.logger import Logger, logging
11 from observer.syncstep import SyncStep
14 from django import setup as django_setup # django 1.7
18 logger = Logger(level=logging.INFO)
20 class PlanetStackConsistencyCheck:
23 self.load_sync_step_modules()
25 def load_sync_step_modules(self, step_dir=None):
27 if hasattr(Config(), "observer_steps_dir"):
28 step_dir = Config().observer_steps_dir
30 step_dir = "/opt/planetstack/observer/steps"
32 for fn in os.listdir(step_dir):
33 pathname = os.path.join(step_dir,fn)
34 if os.path.isfile(pathname) and fn.endswith(".py") and (fn!="__init__.py"):
35 module = imp.load_source(fn[:-3],pathname)
36 for classname in dir(module):
37 c = getattr(module, classname, None)
39 # make sure 'c' is a descendent of SyncStep and has a
40 # provides field (this eliminates the abstract base classes
41 # since they don't have a provides)
43 if inspect.isclass(c) and issubclass(c, SyncStep) and hasattr(c,"provides") and (c not in self.sync_steps):
44 self.sync_steps.append(c)
45 logger.info('loaded sync steps: %s' % ",".join([x.__name__ for x in self.sync_steps]))
52 for step in self.sync_steps:
53 if hasattr(step, "consistency_check"):
54 updated = updated or step(driver=None).consistency_check()
57 logger.info('re-running consistency checks because something changed')
60 if not "-C" in sys.argv:
61 print >> sys.stderr, "You probably wanted to use -C /opt/planetstack/hpc_observer/hpc_observer_config"
63 # Generate command line parser
64 parser = argparse.ArgumentParser(usage='%(prog)s [options]')
65 # smbaker: util/config.py parses sys.argv[] directly to get config file name; include the option here to avoid
66 # throwing unrecognized argument exceptions
67 parser.add_argument('-C', '--config', dest='config_file', action='store', default="/opt/planetstack/plstackapi_config",
68 help='Name of config file.')
69 args = parser.parse_args()
71 if django_setup: # 1.7
74 cc = PlanetStackConsistencyCheck()
77 if __name__ == '__main__':