Example #1
0
    def _process_dates(self, args):
        """ 
            Do the date checkings  and convert them to date time.
            If no dates are provided define an interval of from = now - 1hours and until = now
            
            :Return a tuple (dfrom, duntil)
        """

        dfrom = args.get('from', None)
        duntil = args.get('until', None)

        now = datetime.datetime.utcnow()

        if dfrom:
            dfrom = time_utils.convert_date_str_to_datetime(dfrom)
        else:
            #set default for from: create datetime now - 1 hours
            dfrom = now + datetime.timedelta(hours=-1)

        if duntil:
            #set default for until: create datetime now
            duntil = time_utils.convert_date_str_to_datetime(duntil)
        else:
            #create datetime now
            duntil = now

        #check that from is anterior to until
        if dfrom >= duntil:
            raise Exception(
                "from date (%s) cannot be posterior to until date (%s)" %
                (args.get('from', None), args.get('until', None)))

        return (dfrom, duntil)
Example #2
0
 def _process_dates(self, args):
     """ 
         Do the date checkings  and convert them to date time.
         If no dates are provided define an interval of from = now - 1hours and until = now
         
         :Return a tuple (dfrom, duntil)
     """
     
     dfrom  = args.get('from', None)
     duntil = args.get('until', None)
     
     now = datetime.datetime.utcnow()
     
     if dfrom:
         dfrom  = time_utils.convert_date_str_to_datetime(dfrom)
     else:
         #set default for from: create datetime now - 1 hours
         dfrom =  now + datetime.timedelta(hours=-1)
     
     if duntil:
         #set default for until: create datetime now 
         duntil = time_utils.convert_date_str_to_datetime(duntil)
     else:
         #create datetime now 
         duntil = now 
     
     
     #check that from is anterior to until
     if dfrom >= duntil:
         raise Exception("from date (%s) cannot be posterior to until date (%s)" %(args.get('from', None), args.get('until', None)))
     
     return (dfrom, duntil)
Example #3
0
    def ztest_valid_dates(self):
        """
           test valid dates
        """

        sys.argv = ['/homespace/gaubert/ecli-workspace/rodd/src/eumetsat/dmon/gems_grep.py', \
                    '--from', '2011-04-03T14:30:00', \
                    '--until', '2011-05-04T14:40:00', \
                    "dmon.log"]

        gems_grep = gems_grep_mod.GEMSGrep()

        args = gems_grep.parse_args()

        dfrom, duntil = gems_grep._process_dates(args)

        self.assertEquals(
            dfrom,
            time_utils.convert_date_str_to_datetime("2011-04-03T14:30:00"))

        self.assertEquals(
            duntil,
            time_utils.convert_date_str_to_datetime("2011-05-04T14:40:00"))
Example #4
0
    def ztest_valid_dates(self):
        """
           test valid dates
        """

        sys.argv = [
            "/homespace/gaubert/ecli-workspace/rodd/src/eumetsat/dmon/gems_grep.py",
            "--from",
            "2011-04-03T14:30:00",
            "--until",
            "2011-05-04T14:40:00",
            "dmon.log",
        ]

        gems_grep = gems_grep_mod.GEMSGrep()

        args = gems_grep.parse_args()

        dfrom, duntil = gems_grep._process_dates(args)

        self.assertEquals(dfrom, time_utils.convert_date_str_to_datetime("2011-04-03T14:30:00"))

        self.assertEquals(duntil, time_utils.convert_date_str_to_datetime("2011-05-04T14:40:00"))
Example #5
0
 def run(self, args):
     """
        Run the grep with the given args 
     """
     dfrom, duntil =  self._process_dates(args)
 
     facilities    =  self._process_facilities(args)
     
     extractor     =  gems_feeder.GEMSExtractor(start_time = dfrom, end_time = duntil, facility = facilities, search ='tc-send')
     
     for data_dict in extractor:
         
         fac  = data_dict['facility']
         dt = time_utils.convert_date_str_to_datetime(data_dict['time'])
         time = time_utils.datetime_to_compactdate(dt)
         msg  = data_dict['msg']
         
         print('%s %s %s' %(fac, time , msg))
Example #6
0
    def run(self, args):
        """
           Run the grep with the given args 
        """
        dfrom, duntil = self._process_dates(args)

        facilities = self._process_facilities(args)

        extractor = gems_feeder.GEMSExtractor(start_time=dfrom,
                                              end_time=duntil,
                                              facility=facilities,
                                              search='tc-send')

        for data_dict in extractor:

            fac = data_dict['facility']
            dt = time_utils.convert_date_str_to_datetime(data_dict['time'])
            time = time_utils.datetime_to_compactdate(dt)
            msg = data_dict['msg']

            print('%s %s %s' % (fac, time, msg))