def setup(rootdir): """ Attempt to configure environment by locating 'bootstrap.py' in ``rootdir`` or by searching parent folders relative to ``rootdir``. """ rootdir = os.path.abspath(rootdir) if os.path.isfile(os.path.join(rootdir, "bootstrap.py")): sys.path.append(rootdir) import bootstrap bootstrap.setup(rootdir, "hgt.log") else: head, tail = os.path.split(rootdir) if head and tail: setup(head) else: raise RuntimeError("Could not locate bootstrap.py")
def load_from_file(path, **kw): try: kw = bootstrap.setup(**kw) except Exception as e: raise e else: # initialize the redis connection redis_conn = kw.get("redis_conn") # first unpickle the file into a list of objects dump_data = pickle.load(open(path, "rb")) for key in dump_data: load_key(key, redis_conn) bootstrap.breakdown(**kw)
def dump(**kw): try: # set up the connection wit the passed parameters kw = bootstrap.setup(**kw) except Exception as e: raise e else: redis_conn = kw.get("redis_conn") dump_data = [] # now loop through each key and remove from the database for key in redis_conn.keys(): dump_data.append(get_key(key, redis_conn)) # breakdown test environment here bootstrap.breakdown(**kw) return dump_data