587
|
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. """
|
628
|
32 |
input_ = open(sysdef, 'r')
|
|
33 |
for line in input_.readlines():
|
587
|
34 |
result = MATCH_ENTITY.match(line)
|
|
35 |
if result != None:
|
628
|
36 |
input_.close()
|
587
|
37 |
return result.groups()[0]
|
628
|
38 |
input_.close()
|
587
|
39 |
print 'layer_real_source_path entity not found in ' + sysdef
|
|
40 |
return None
|
|
41 |
|
|
42 |
|
|
43 |
def get_first_day_of_cycle(now = datetime.datetime.now()):
|
|
44 |
""" This function returns a datetime object representing the monday from closest
|
|
45 |
odd week.
|
|
46 |
"""
|
588
|
47 |
_, isoweek, isoday = now.isocalendar()
|
587
|
48 |
week = isoweek - 1
|
|
49 |
day = isoday - 1
|
|
50 |
monday = now - datetime.timedelta(days=day + week.__mod__(2) * 7)
|
|
51 |
monday = monday.replace(hour = 0, minute = 0, second = 0, microsecond = 0)
|
|
52 |
return monday
|
|
53 |
|
|
54 |
def get_absolute_date(day, time, now = datetime.datetime.now()):
|
|
55 |
""" Get the absolute date from the day and time. """
|
|
56 |
time = datetime.datetime.strptime(time, "%H:%M")
|
|
57 |
delta = datetime.timedelta(days = day-1, hours = time.hour, minutes= time.minute)
|
|
58 |
return get_first_day_of_cycle(now) + delta
|
|
59 |
|
|
60 |
|
|
61 |
def is_in_interval(day1, time1, day2, time2, now = datetime.datetime.now()):
|
|
62 |
""" Return True is get_absolute_date(day1, time1) < now < get_absolute_date(day2, time2). """
|
|
63 |
delta1 = get_absolute_date(day1, time1, now)
|
|
64 |
delta2 = get_absolute_date(day2, time2, now)
|
|
65 |
if now <= delta1:
|
|
66 |
return False
|
|
67 |
if delta2 <= now:
|
|
68 |
return False
|
|
69 |
return True
|
|
70 |
|