Module ido |
[hide private]
[frames] | no frames]

# Source Code for Module ido

     1  #============================================================================
     2  #Name        : ido.py
     3  #Part of     : Helium
     4
     5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     6  #All rights reserved.
     7  #This component and the accompanying materials are made available
     8  #under the terms of the License "Eclipse Public License v1.0"
     9  #which accompanies this distribution, and is available
    10  #at the URL "http://www.eclipse.org/legal/epl-v10.html".
    11  #
    12  #Initial Contributors:
    13  #Nokia Corporation - initial contribution.
    14  #
    15  #Contributors:
    16  #
    17  #Description:
    18  #===============================================================================
    19
    20  """
    21  IDO specific features
    22      * find layer_real_source_path from sysdef file.
    23      * time manipulation for robot releasing.
    24  """
    25  import re
    26  import datetime
    27
    28  MATCH_ENTITY = re.compile(r".*ENTITY\s+layer_real_source_path\s+\"(.+)\"\s*>?.*")
    29
    30 -def get_sysdef_location(sysdef):
    31      """ Search for layer_real_source_path entity inside the sysdef file. """
    32      input = open(sysdef, 'r')
    33      for line in input.readlines():
    34          result = MATCH_ENTITY.match(line)
    35          if result != None:
    36              input.close()
    37              return result.groups()[0]
    38      input.close()
    39      return None
    40
    41
    42 -def get_first_day_of_cycle(now = datetime.datetime.now()):
    43      """ This function returns a datetime object representing the monday from closest
    44          even week.
    45      """
    46      week = int(now.strftime("%W"))
    47      day = int(now.strftime("%w")) - 1
    48      monday = now - datetime.timedelta(days=day + week.__mod__(2) * 7)
    49      monday = monday.replace(hour = 0, minute = 0, second = 0, microsecond = 0)
    50      return monday
    51
    52 -def get_absolute_date(day, time, now = datetime.datetime.now()):
    53      """ Get the absolute date from the day and time. """
    54      time = datetime.datetime.strptime(time, "%H:%M")
    55      delta = datetime.timedelta(days = day-1, hours = time.hour, minutes= time.minute)
    56      return get_first_day_of_cycle(now) + delta
    57
    58
    59 -def is_in_interval(day1, time1, day2, time2, now = datetime.datetime.now()):
    60      """ Return True is get_absolute_date(day1, time1) < now < get_absolute_date(day2, time2). """
    61      delta1 = get_absolute_date(day1, time1, now)
    62      delta2 = get_absolute_date(day2, time2, now)
    63      if now <= delta1:
    64          return False
    65      if delta2 <= now:
    66          return False
    67      return True
    68