#!/usr/bin/env python # -*- coding: utf-8 -*- # ==================================================================== # # Author: Sonia Labetoulle # # Contact: sonia.labetoulle _at_ ipsl.jussieu.fr # # Created: 2016 # # History: # # Modification: # # ==================================================================== # """ Rename files from : - TGCC "ccc_myproject" (ccc_myproject.dat_20150602) - IDRIS "cpt" (compta_20151206_0643.dat) to a common nomenclature: => cpt_[center]_[project]_[ssaammjj]_[hhmm].dat """ # this must come first from __future__ import print_function, unicode_literals, division # standard library imports import os import glob import shutil ####################################################################### if __name__ == '__main__': dirin = "/home_local/slipsl/ConsoGENCMIP6/init_db/data" dirout = "/home_local/slipsl/ConsoGENCI/data" file_list = glob.glob(os.path.join(dirin, "*.dat*")) for src in file_list: filein = os.path.basename(src) if "ccc_myproject" in filein: centre = "tgcc" projet = "gencmip6" _, _, date = filein.split("_") heure = "2359" elif "compta" in filein: centre = "idris" projet = "rgzi" _, date, heure = filein.split("_") heure, _ = heure.split(".") fileout = "cpt_{}_{}_{}_{}.dat".format(centre, projet, date, heure) dst = os.path.join(dirout, centre, projet, fileout) if not os.path.isfile(dst): print("copy {} to\n {}".format(src, dst)) shutil.copy(src, dst)