Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
domotikad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
domotika
domotikad
Commits
b31e04fa
Commit
b31e04fa
authored
Feb 04, 2014
by
nextime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added "ANY" keyword to statuses
parent
0ca7f86f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
13 deletions
+96
-13
parsers.py
domotika/parsers.py
+96
-13
No files found.
domotika/parsers.py
View file @
b31e04fa
...
@@ -87,9 +87,19 @@ def statusParser(trigger, sun, restype='string'):
...
@@ -87,9 +87,19 @@ def statusParser(trigger, sun, restype='string'):
return
dmdb
.
Registry
.
DBPOOL
.
runQuery
(
sqlstring
)
.
addCallback
(
parseReturn
,
reverse
)
return
dmdb
.
Registry
.
DBPOOL
.
runQuery
(
sqlstring
)
.
addCallback
(
parseReturn
,
reverse
)
oneatleast
=
False
reverse
=
False
reverse
=
False
if
trigger
.
startswith
(
"REV "
)
or
trigger
.
startswith
(
"REV:"
)
and
restype
!=
'string'
:
if
((
trigger
.
startswith
(
"REV ANY "
)
or
trigger
.
startswith
(
"REV:ANY:"
)
or
trigger
.
startswith
(
"ANY REV "
)
or
trigger
.
startswith
(
"ANY:REV:"
))
and
restype
!=
'string'
):
reverse
=
True
reverse
=
True
oneatleast
=
True
trigger
=
trigger
[
8
:]
elif
trigger
.
startswith
(
"REV "
)
or
trigger
.
startswith
(
"REV:"
)
and
restype
!=
'string'
:
reverse
=
True
trigger
=
trigger
[
4
:]
elif
trigger
.
startswith
(
"ANY "
)
or
trigger
.
startswith
(
"ANY:"
)
and
restype
!=
'string'
:
oneatleast
=
True
trigger
=
trigger
[
4
:]
trigger
=
trigger
[
4
:]
if
not
reverse
:
if
not
reverse
:
...
@@ -101,13 +111,15 @@ def statusParser(trigger, sun, restype='string'):
...
@@ -101,13 +111,15 @@ def statusParser(trigger, sun, restype='string'):
if
restype
==
'int'
:
if
restype
==
'int'
:
defres
=
1
defres
=
1
ret
=
defer
.
succeed
(
defres
)
ret
=
defer
.
succeed
(
defres
)
if
trigger
.
startswith
(
"FILE "
)
or
trigger
.
startswith
(
"FILE:"
):
if
trigger
.
startswith
(
"FILE "
)
or
trigger
.
startswith
(
"FILE:"
):
if
os
.
path
.
isfile
(
trigger
[
5
:]
.
split
()[
0
]):
if
os
.
path
.
isfile
(
trigger
[
5
:]
.
split
()[
0
]):
f
=
open
(
trigger
[
5
:]
.
split
()[
0
],
"r"
)
f
=
open
(
trigger
[
5
:]
.
split
()[
0
],
"r"
)
ret
=
defer
.
succeed
(
parseReturn
(
f
.
read
(),
reverse
))
ret
=
defer
.
succeed
(
parseReturn
(
f
.
read
(),
reverse
))
f
.
close
()
f
.
close
()
if
trigger
.
startswith
(
"FILEEXISTS "
)
or
trigger
.
startswith
(
"FILEEXISTS:"
):
el
if
trigger
.
startswith
(
"FILEEXISTS "
)
or
trigger
.
startswith
(
"FILEEXISTS:"
):
if
os
.
path
.
isfile
(
trigger
[
11
:]
.
split
()[
0
]):
if
os
.
path
.
isfile
(
trigger
[
11
:]
.
split
()[
0
]):
ret
=
defer
.
succeed
(
parseReturn
(
'1'
,
reverse
))
ret
=
defer
.
succeed
(
parseReturn
(
'1'
,
reverse
))
else
:
else
:
...
@@ -137,7 +149,16 @@ def statusParser(trigger, sun, restype='string'):
...
@@ -137,7 +149,16 @@ def statusParser(trigger, sun, restype='string'):
pass
pass
elif
len
(
tid
)
>
0
and
len
(
tid
[
0
])
>
0
:
elif
len
(
tid
)
>
0
and
len
(
tid
[
0
])
>
0
:
try
:
try
:
ret
=
doQuery
(
"SELECT IF(SUM(active)>0,1,0) from timers WHERE DMDOMAIN(timer_name, '"
+
str
(
tid
[
0
])
+
"')=1"
)
if
not
oneatleast
:
if
not
reverse
:
ret
=
doQuery
(
"SELECT MIN(active) from timers WHERE DMDOMAIN(timer_name, '"
+
str
(
tid
[
0
])
+
"')=1"
)
# All active?
else
:
ret
=
doQuery
(
"SELECT MAX(active) from timers WHERE DMDOMAIN(timer_name, '"
+
str
(
tid
[
0
])
+
"')=1"
,
reverse
=
True
)
# all off?
else
:
if
not
reverse
:
ret
=
doQuery
(
"SELECT MAX(active) from timers WHERE DMDOMAIN(timer_name, '"
+
str
(
tid
[
0
])
+
"')=1"
)
# at least one active?
else
ret
=
doQuery
(
"SELECT MIN(active) from timers WHERE DMDOMAIN(timer_name, '"
+
str
(
tid
[
0
])
+
"')=1"
,
reverse
=
True
)
# at least one off?
except
:
except
:
pass
pass
elif
trigger
.
startswith
(
"ACTIONACTIVE "
)
or
trigger
.
startswith
(
"ACTIONACTIVE:"
):
elif
trigger
.
startswith
(
"ACTIONACTIVE "
)
or
trigger
.
startswith
(
"ACTIONACTIVE:"
):
...
@@ -149,17 +170,43 @@ def statusParser(trigger, sun, restype='string'):
...
@@ -149,17 +170,43 @@ def statusParser(trigger, sun, restype='string'):
pass
pass
elif
len
(
aid
)
>
0
and
len
(
aid
[
0
])
>
0
:
elif
len
(
aid
)
>
0
and
len
(
aid
[
0
])
>
0
:
try
:
try
:
ret
=
doQuery
(
"SELECT IF(SUM(active)>0,1,0) from actions WHERE DMDOMAIN(action_name, '"
+
str
(
aid
[
0
])
+
"')=1"
)
if
not
oneatleast
:
if
not
reverse
:
ret
=
doQuery
(
"SELECT MIN(active) from actions WHERE DMDOMAIN(action_name, '"
+
str
(
tid
[
0
])
+
"')=1"
)
# All active?
else
:
ret
=
doQuery
(
"SELECT MAX(active) from actions WHERE DMDOMAIN(action_name, '"
+
str
(
tid
[
0
])
+
"')=1"
,
reverse
=
True
)
# all off?
else
:
if
not
reverse
:
ret
=
doQuery
(
"SELECT MAX(active) from actions WHERE DMDOMAIN(action_name, '"
+
str
(
tid
[
0
])
+
"')=1"
)
# at least one active?
else
ret
=
doQuery
(
"SELECT MIN(active) from actions WHERE DMDOMAIN(action_name, '"
+
str
(
tid
[
0
])
+
"')=1"
,
reverse
=
True
)
# at least one off?
except
:
except
:
pass
pass
elif
trigger
.
startswith
(
"BOARDSTATUS "
)
or
trigger
.
startswith
(
"BOARDSTATUS:"
):
elif
(
trigger
.
startswith
(
"BOARDSTATUS "
)
or
trigger
.
startswith
(
"BOARDSTATUS:"
)
# DEPRECATED, USE BOARDACTIVE
trigger
.
startswith
(
"BOARDACTIVE "
)
or
trigger
.
startswith
(
"BOARDACTIVE:"
)):
bname
=
trigger
[
12
:]
.
split
()
bname
=
trigger
[
12
:]
.
split
()
if
len
(
bname
)
>
0
:
if
len
(
bname
)
>
0
:
try
:
try
:
ret
=
doQuery
(
"SELECT online FROM dmboards WHERE name='"
+
str
(
bname
[
0
])
+
"'"
,
reverse
)
ret
=
doQuery
(
"SELECT online FROM dmboards WHERE name='"
+
str
(
bname
[
0
])
+
"'"
,
reverse
)
except
:
except
:
pass
pass
else
:
try
:
if
not
oneatleast
:
if
not
reverse
:
ret
=
doQuery
(
"SELECT MIN(online) FROM dmboards"
)
else
:
ret
=
doQuery
(
"SELECT MAX(online) FROM dmboards"
,
True
)
else
:
if
not
reverse
:
ret
=
doQuery
(
"SELECT MAX(online) FROM dmboards"
)
else
:
ret
=
doQuery
(
"SELECT MIN(online) FROM dmboards"
,
True
)
except
:
pass
elif
trigger
.
startswith
(
"INPSTATUS "
)
or
trigger
.
startswith
(
"INPSTATUS:"
):
elif
trigger
.
startswith
(
"INPSTATUS "
)
or
trigger
.
startswith
(
"INPSTATUS:"
):
tid
=
trigger
[
10
:]
.
split
()
tid
=
trigger
[
10
:]
.
split
()
if
len
(
tid
)
>
0
and
genutils
.
is_number
(
tid
[
0
]):
if
len
(
tid
)
>
0
and
genutils
.
is_number
(
tid
[
0
]):
...
@@ -260,21 +307,57 @@ def statusParser(trigger, sun, restype='string'):
...
@@ -260,21 +307,57 @@ def statusParser(trigger, sun, restype='string'):
if
len
(
dmd
)
>
1
and
genutils
.
is_number
(
dmd
[
1
]):
if
len
(
dmd
)
>
1
and
genutils
.
is_number
(
dmd
[
1
]):
dmctx
=
" AND relay.ctx='"
+
dmd
[
1
]
+
"'"
dmctx
=
" AND relay.ctx='"
+
dmd
[
1
]
+
"'"
try
:
try
:
if
reverse
:
if
not
oneatleast
:
ret
=
doQuery
(
"""select IF(max(relstatus.status)>0,0,1) from relstatus,relay where
if
not
reverse
:
relstatus.buttonid=relay.id AND DMDOMAIN(relay.domain,'"""
+
str
(
dmd
[
0
])
+
"')=1"
+
dmctx
,
reverse
=
False
)
ret
=
doQuery
(
"""select min(relstatus.status) from relstatus,relay where
relstatus.buttonid=relay.id AND DMDOMAIN(relay.domain,'"""
+
str
(
dmd
[
0
])
+
"')=1"
+
dmctx
,
reverse
=
False
)
# all closed
else
:
ret
=
doQuery
(
"""select max(relstatus.status) from relstatus,relay where
relstatus.buttonid=relay.id AND DMDOMAIN(relay.domain,'"""
+
str
(
dmd
[
0
])
+
"')=1"
+
dmctx
,
reverse
=
True
)
# all open
else
:
if
not
reverse
:
ret
=
doQuery
(
"""select max(relstatus.status) from relstatus,relay where
relstatus.buttonid=relay.id AND DMDOMAIN(relay.domain,'"""
+
str
(
dmd
[
0
])
+
"')=1"
+
dmctx
,
reverse
=
False
)
# at least one closed
else
:
else
:
ret
=
doQuery
(
"""select min(relstatus.status) from relstatus,relay where
ret
=
doQuery
(
"""select min(relstatus.status) from relstatus,relay where
relstatus.buttonid=relay.id AND DMDOMAIN(relay.domain,'"""
+
str
(
dmd
[
0
])
+
"')=1"
+
dmctx
,
reverse
=
False
);
relstatus.buttonid=relay.id AND DMDOMAIN(relay.domain,'"""
+
str
(
dmd
[
0
])
+
"')=1"
+
dmctx
,
reverse
=
True
)
# at least one open
except
:
pass
elif
trigger
.
startswith
(
"ACTDOMAIN "
)
or
trigger
.
startswith
(
"ACTDOMAIN:"
):
if
':'
in
trigger
:
dmd
=
trigger
[
10
:]
.
split
(
":"
)
else
:
dmd
=
trigger
[
10
:]
.
split
()
try
:
if
not
oneatleast
:
if
not
reverse
:
ret
=
doQuery
(
"""select min(actstatus.status) from actstatus,actions where
actstatus.buttonid=actions.id AND DMDOMAIN(actions.action_name,'"""
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
False
)
# all true
else
:
ret
=
doQuery
(
"""select max(actstatus.status) from actstatus,actions where
actstatus.buttonid=actions.id AND DMDOMAIN(actions.action_name,'"""
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
True
)
# all false
else
:
if
not
reverse
:
ret
=
doQuery
(
"""select max(actstatus.status) from actstatus,actions where
actstatus.buttonid=actions.id AND DMDOMAIN(actions.action_name,'"""
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
False
)
# at least one true
else
:
ret
=
doQuery
(
"""select min(actstatus.status) from actstatus,actions where
actstatus.buttonid=actions.id AND DMDOMAIN(actions.action_name,'"""
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
True
)
# at least one false
except
:
except
:
pass
pass
elif
trigger
.
startswith
(
"INPDOMAIN "
)
or
trigger
.
startswith
(
"INPDOMAIN:"
):
elif
trigger
.
startswith
(
"INPDOMAIN "
)
or
trigger
.
startswith
(
"INPDOMAIN:"
):
dmd
=
trigger
[
10
:]
.
split
()
dmd
=
trigger
[
10
:]
.
split
()
try
:
try
:
if
reverse
:
if
not
oneatleast
:
ret
=
doQuery
(
"select IF(max(status)>0,0,1) FROM inpstatus WHERE DMDOMAIN(inpname, '"
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
False
)
if
not
reverse
:
ret
=
doQuery
(
"select MIN(status) FROM inpstatus WHERE DMDOMAIN(inpname, '"
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
False
)
# all close
else
:
ret
=
doQuery
(
"select MAX(status) FROM inpstatus WHERE DMDOMAIN(inpname, '"
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
True
)
# all open
else
:
if
not
reverse
:
ret
=
doQuery
(
"select MAX(status) FROM inpstatus WHERE DMDOMAIN(inpname, '"
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
False
)
# at least one close
else
:
else
:
ret
=
doQuery
(
"select min(status) FROM inpstatus WHERE DMDOMAIN(inpname, '"
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
False
)
ret
=
doQuery
(
"select MIN(status) FROM inpstatus WHERE DMDOMAIN(inpname, '"
+
str
(
dmd
[
0
])
+
"')=1"
,
reverse
=
True
)
# at least one open
except
:
except
:
pass
pass
elif
trigger
.
startswith
(
"NETSTATUS"
):
elif
trigger
.
startswith
(
"NETSTATUS"
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment