From a70a697b101193908d779e06132884c83ab1d0c6 Mon Sep 17 00:00:00 2001 From: Romain Broucquart <romain.broucquart@synchrotron-soleil.fr> Date: Fri, 26 Jun 2020 11:05:32 +0200 Subject: [PATCH] =?UTF-8?q?[ArchiveExtractor]=20Ajoute=20la=20fonctionnali?= =?UTF-8?q?t=C3=A9=20filemode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Permet de préciser l'option --filemode * Dans ce cas, lit dans un fichier la liste des attributs --- ArchiveExtractor.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/ArchiveExtractor.py b/ArchiveExtractor.py index 1e4fef8..a87cb05 100755 --- a/ArchiveExtractor.py +++ b/ArchiveExtractor.py @@ -291,11 +291,17 @@ if __name__ == "__main__": help="Extractor device number, default: %(default)s") parser.add_argument("--fileout", type=str, default="extracted_%s.npy"%datetime.datetime.now().strftime("%Y%m%d_%H%M%S"), - help="filename of the extraction destination. Default: %(default)s"), + help="filename of the extraction destination. Default: %(default)s"), parser.add_argument('--log', type=str, default="INFO", help="Log level. Default: %(default)s.") + + parser.add_argument('--filemode', action="store_true", + help="Set attribute to filemode."+ + " Instead of specifying attributes, put a path to a file containing a list of attributes."+ + " The file contains one attribute per line.") + parser.add_argument('attributes', type=str, nargs='+', help="List of attributes to extract. Full tango path.") @@ -316,6 +322,23 @@ if __name__ == "__main__": logger.debug("Parsed arguments: %s"%args) + ####################################################### + # Filemode or not + if args.filemode: + logger.info("Filemode, openning file %s"%args.attributes[0]) + # Read the file. Each line is an attribute + with open(args.attributes[0], "r") as fp: + attributes = fp.readlines() + + logger.debug("Read lines : %s"%attributes) + + # Clean end of line + for i_a in range(len(attributes)): + attributes[i_a] = attributes[i_a].rstrip() + + else: + attributes = args.attributes + ####################################################### # Select Extractor extractor = "archiving/%sDBExtractor/%d"%(args.DB, args.DBN) @@ -328,7 +351,7 @@ if __name__ == "__main__": # Extract from database logger.info("Extract from %s to %s."%(args.dateStart, args.dateStop)) - for attr in args.attributes: + for attr in attributes: logger.info("Extracting attribute %s..."%attr) try: -- GitLab