source: TOOLS/ConsoGENCI/trunk/misc/rename_cpt.py @ 4183

Last change on this file since 4183 was 2775, checked in by labetoulle, 8 years ago

Overall cleaning and refactoring

  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# ==================================================================== #
5# Author: Sonia Labetoulle                                             #
6# Contact: sonia.labetoulle _at_ ipsl.jussieu.fr                       #
7# Created: 2016                                                        #
8# History:                                                             #
9# Modification:                                                        #
10# ==================================================================== #
11
12"""
13  Rename files from :
14    - TGCC "ccc_myproject" (ccc_myproject.dat_20150602)
15    - IDRIS "cpt" (compta_20151206_0643.dat)
16  to a common nomenclature:
17    => cpt_[center]_[project]_[ssaammjj]_[hhmm].dat
18"""
19
20# this must come first
21from __future__ import print_function, unicode_literals, division
22
23# standard library imports
24import os
25import glob
26import shutil
27
28
29#######################################################################
30if __name__ == '__main__':
31
32  dirin = "/home_local/slipsl/ConsoGENCMIP6/init_db/data"
33  dirout = "/home_local/slipsl/ConsoGENCI/data"
34  file_list = glob.glob(os.path.join(dirin, "*.dat*"))
35
36  for src in file_list:
37    filein = os.path.basename(src)
38
39    if "ccc_myproject" in filein:
40      centre = "tgcc"
41      projet = "gencmip6"
42      _, _, date = filein.split("_")
43      heure  = "2359"
44    elif "compta" in filein:
45      centre = "idris"
46      projet = "rgzi"
47      _, date, heure = filein.split("_")
48      heure, _ = heure.split(".")
49
50    fileout = "cpt_{}_{}_{}_{}.dat".format(centre, projet, date, heure)
51    dst = os.path.join(dirout, centre, projet, fileout)
52
53    if not os.path.isfile(dst):
54      print("copy {} to\n     {}".format(src, dst))
55      shutil.copy(src, dst)
Note: See TracBrowser for help on using the repository browser.