Lines 1008-1084
def sambaWorkstationsUnmap(workstations):
|
Link Here
|
---|
|
1008 |
return string.split(workstations[0],',') |
1008 |
return string.split(workstations[0],',') |
1009 |
|
1009 |
|
1010 |
def logonHoursMap(logontimes): |
1010 |
def logonHoursMap(logontimes): |
1011 |
"converts the bitfield 001110010110...100 to the respective string" |
1011 |
"""Converts array of bits set to an hex-string.""" |
1012 |
|
1012 |
octets = [0] * (24 * 7 / 8) |
1013 |
# convert list of bit numbers to bit-string |
|
|
1014 |
# bitstring = '0' * 168 |
1015 |
bitstring = ''.join( map( lambda x: x in logontimes and '1' or '0', range( 168 ) ) ) |
1016 |
|
1017 |
# for idx in logontimes: |
1018 |
# bitstring[ idx ] = '1' |
1019 |
|
1020 |
logontimes = bitstring |
1021 |
|
1022 |
# the order of the bits of each byte has to be reversed. The reason for this is that |
1013 |
# the order of the bits of each byte has to be reversed. The reason for this is that |
1023 |
# consecutive bytes mean consecutive 8-hrs-intervals, but the leftmost bit stands for |
1014 |
# consecutive bytes mean consecutive 8-hrs-intervals, but the MSB stands for |
1024 |
# the last hour in that interval, the 2nd but leftmost bit for the second-but-last |
1015 |
# the last hour in that interval, the 2nd leftmost bit for the second-to-last |
1025 |
# hour and so on. We want to hide this from anybody using this feature. |
1016 |
# hour and so on. We want to hide this from anybody using this feature. |
1026 |
# See http://ma.ph-freiburg.de/tng/tng-technical/2003-04/msg00015.html for details. |
1017 |
# See <http://ma.ph-freiburg.de/tng/tng-technical/2003-04/msg00015.html> for details. |
1027 |
|
1018 |
for hour in logontimes: |
1028 |
newtimes = "" |
1019 |
idx, bit = divmod(hour, 8) |
1029 |
for i in range(0,21): |
1020 |
octets[idx] |= 1 << bit |
1030 |
bitlist=list(logontimes[(i*8):(i*8)+8]) |
1021 |
return ''.join(['%02x' % _ for _ in octets]) |
1031 |
bitlist.reverse() |
|
|
1032 |
newtimes+="".join(bitlist) |
1033 |
logontimes = newtimes |
1034 |
|
1035 |
# create a hexnumber from each 8-bit-segment |
1036 |
ret="" |
1037 |
for i in range(0,21): |
1038 |
val=0 |
1039 |
exp=7 |
1040 |
for j in range((i*8), (i*8)+8): |
1041 |
if not (logontimes[j]=="0"): |
1042 |
val+=2**exp |
1043 |
exp-=1 |
1044 |
# we now have: 0<=val<=255 |
1045 |
hx=hex(val)[2:4] |
1046 |
if len(hx)==1: hx="0"+hx |
1047 |
ret+=hx |
1048 |
|
1049 |
return ret |
1050 |
|
1022 |
|
1051 |
def logonHoursUnmap(logontimes): |
1023 |
def logonHoursUnmap(logontimes): |
1052 |
"converts the string to a bit array" |
1024 |
"""Converts hex-string to an array of bits set.""" |
1053 |
|
1025 |
times = logontimes[0].ljust(42, '0')[:42] |
1054 |
times=logontimes[0][:42] |
1026 |
assert len(times) == 24 * 7 / 4 |
1055 |
while len(times)<42: |
1027 |
octets = [int(times[i : i + 2], 16) for i in range(0, len(times), 2)] |
1056 |
times=times |
1028 |
assert len(octets) == 24 * 7 / 8 |
1057 |
ret="" |
1029 |
return [idx * 8 + bit |
1058 |
for i in range(0,42,2): |
1030 |
for (idx, value) in enumerate(octets) |
1059 |
val=int(times[i:i+2],16) |
1031 |
for bit in range(8) |
1060 |
ret+=intToBinary(val) |
1032 |
if value & (1 << bit)] |
1061 |
|
|
|
1062 |
# reverse order of the bits in each byte. See above for details |
1063 |
newtime = "" |
1064 |
for i in range(0, 21): |
1065 |
bitlist=list(ret[(i*8):(i*8)+8]) |
1066 |
bitlist.reverse() |
1067 |
newtime+="".join(bitlist) |
1068 |
|
1069 |
# convert bit-string to list |
1070 |
return filter( lambda i: newtime[ i ] == '1', range( 168 ) ) |
1071 |
|
1072 |
def intToBinary(val): |
1073 |
ret="" |
1074 |
while val>0: |
1075 |
ret=str(val&1)+ret |
1076 |
val=val>>1 |
1077 |
# pad with leading 0s until length is n*8 |
1078 |
if ret=="": ret="0" |
1079 |
while not (len(ret)%8==0): |
1080 |
ret="0"+ret |
1081 |
return ret |
1082 |
|
1033 |
|
1083 |
def GMTOffset(): |
1034 |
def GMTOffset(): |
1084 |
# returns the difference in hours between local time and GMT (is -1 for CET and CEST) |
1035 |
# returns the difference in hours between local time and GMT (is -1 for CET and CEST) |