#!/usr/bin/python3 import os import sys from nitpo import Nitpo class Infile(Nitpo): def __init__(self, do_verbose=False): """simple class to extract repis""" super().__init__() if not self.has_conf('ext', 'repis'): print("infile needs [ext][repis] defined.", file=sys.stderr) sys.exit() self.len_ext = len(self.conf['ext']['repis']) if not self.has_conf('chars', 'repisep'): print("infile needs [char][repisep] defined.", file=sys.stderr) sys.exit() self.repisep = self.conf['chars']['repisep'] # self.suredo = Suredo() self.do_verbose = do_verbose def bana_chop_ext(self, fufi): bana = os.path.basename(fufi) len_ext = self.len_ext if bana.endswith('.gz'): bana = bana[0:-3] bana = bana[0:-len_ext] return bana def get_prior(self, fufi): bana = os.path.basename(fufi) parts = bana.partition(self.repisep) return parts[0] def get_repcode(self, fufi): bana = os.path.basename(fufi) parts = bana.partition(self.repisep) after_prior = parts[2] count_chop = self.len_ext if after_prior.endswith('.gz'): count_chop += 3 elif after_prior.endswith('.txt'): count_chop = 4 repcode = after_prior[0:-count_chop] return repcode def is_it(self, fufi): test_fufi = fufi if fufi.endswith('.gz'): test_fufi = fufi[0:-3] if test_fufi.endswith(self.conf['ext']['repis']): return True return False def get_issuedate(self, fufi): return os.path.basename(os.path.dirname(fufi)) def get_base(self, fufi): issuedate = self.get_issuedate(fufi) bana = self.bana_chop_ext(fufi) base = issuedate + '/' + bana return base