#!/usr/bin/python import os origin_dir = "/mnt/ceph/schrodinger/log/origin" output_dir = "/mnt/ceph/schrodinger/log/hash" by_name_dir = "/mnt/ceph/schrodinger/log/by_name" def get_cluster_and_pod(src): pod = src.split("_")[0] cluster = src.split("_")[1] return pod, cluster def make_link(src, dst): dirname = os.path.dirname(dst) mkdirs(dirname) print src, os.path.dirname(dst) os.symlink(src, dst) def mkdirs(dirname): if not os.path.exists(dirname): os.makedirs(dirname) def get_dst(src): container_id = src.split("-")[-1] path = container_id[0] + "/" + container_id[1:3] + "/" + container_id return output_dir + "/" + path def list_path(src): return os.listdir(src) def run(): for f in list_path(origin_dir): try: dst = get_dst(f) make_link(origin_dir + "/" +f, dst) except Exception as e: pass try: pod, cluster = get_cluster_and_pod(f) make_link(origin_dir + "/" +f, by_name_dir + "/" + cluster + "/" + pod) except Exception as e: pass if __name__ == "__main__": run()