Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Penguidom
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
domotika
Penguidom
Commits
981f368f
Commit
981f368f
authored
Jan 05, 2018
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Structure plugin communications
parent
cc1d3454
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
187 additions
and
1010 deletions
+187
-1010
.gitignore
.gitignore
+2
-1
imodules.py
penguidom/imodules.py
+42
-0
penguidom.py
penguidom/penguidom.py
+6
-1
pluggable.py
penguidom/pluggable.py
+87
-0
__init__.py
penguidom/plugins/__init__.py
+32
-0
__init__.py
penguidom/plugins/paradox/__init__.py
+3
-0
paradox.py
penguidom/plugins/paradox/paradox.py
+13
-1008
penguidomd
penguidomd
+2
-0
No files found.
.gitignore
View file @
981f368f
...
...
@@ -12,4 +12,5 @@ conf/*.conf
ssl/*.key
logs/*
run/*
penguidom/plugins/*/dropin.cache
*.old.py
penguidom/imodules.py
0 → 100644
View file @
981f368f
###########################################################################
# Copyright (c) 2018- Franco (nextime) Lanza <franco@unixmedia.it>
#
# Penguidom System Controller Daemon "penguidomd"
#
# This file is part of penguidomd.
#
# penguidomd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from
zope.interface
import
Interface
,
Attribute
from
zope.interface
import
implements
from
twisted.python
import
reflect
import
logging
from
dmlib
import
constants
as
C
log
=
logging
.
getLogger
(
'Plugins'
)
class
IModules
(
Interface
):
""" Base module interface """
def
initialize
(
self
,
callback
,
logger
):
""" initialize a plugin module passing a callback """
def
context2section
(
ctx
):
if
int
(
ctx
)
in
C
.
SECTIONS
.
keys
():
section
=
C
.
SECTIONS
[
int
(
ctx
)]
else
:
section
=
"none"
return
section
penguidom/penguidom.py
View file @
981f368f
...
...
@@ -39,6 +39,7 @@ import struct
from
dmlib
import
dmdomain
from
singleton
import
Singleton
import
pluggable
import
ikap
...
...
@@ -98,11 +99,15 @@ class penguidomService(service.Service):
log
.
debug
(
"isStarted() called"
)
self
.
isConfigured
()
def
isConfigured
(
self
):
self
.
initializePlugins
()
self
.
initialized
=
True
log
.
debug
(
"isConfigured() called"
)
def
initializePlugins
(
self
):
self
.
plugins
=
pluggable
.
Loader
(
ConvenienceCaller
(
lambda
c
:
self
.
_callback
(
'plugin'
,
c
)))
def
getIkapUDP
(
self
):
caller
=
ConvenienceCaller
(
lambda
c
:
self
.
_callback
(
'ikap'
,
c
))
self
.
udp
=
ikap
.
DomIkaUDP
(
caller
)
...
...
penguidom/pluggable.py
0 → 100644
View file @
981f368f
import
logging
import
os
,
sys
import
imodules
,
plugins
from
nexlibs.utils.genutils
import
ConvenienceCaller
log
=
logging
.
getLogger
(
'Plugins'
)
try
:
from
twisted.plugin
import
IPlugin
,
getPlugins
except
ImportError
:
pass
else
:
list
(
getPlugins
(
imodules
.
IModules
,
plugins
))
# To refresh cache
PLUGINDIR
=
os
.
path
.
join
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
sys
.
argv
[
0
])),
'penguidom'
,
'plugins'
)
def
getPlugin
(
name
,
core
=
False
):
for
p
in
getPlugins
(
imodules
.
IModules
,
plugins
):
qual
=
"
%
s.
%
s"
%
(
p
.
__module__
,
p
.
__class__
.
__name__
)
log
.
info
(
"Loading plugin "
+
qual
)
if
p
.
__module__
.
split
(
'.'
)[
-
1
]
==
name
:
p
.
core
=
core
return
p
return
None
class
PluginLogger
(
object
):
def
__init__
(
self
,
plugname
):
self
.
name
=
plugname
def
_format
(
self
,
what
):
return
str
(
self
.
name
)
+
": "
+
what
def
info
(
self
,
what
):
log
.
info
(
self
.
_format
(
what
))
def
error
(
self
,
what
):
log
.
error
(
self
.
_format
(
what
))
def
warning
(
self
,
what
):
log
.
warning
(
self
.
_format
(
what
))
def
debug
(
self
,
what
):
log
.
debug
(
self
.
_format
(
what
))
class
Loader
(
object
):
plugreg
=
{}
def
__init__
(
self
,
core
):
log
.
info
(
"Initializing Plugins..."
)
self
.
core
=
core
for
name
in
os
.
listdir
(
PLUGINDIR
):
plugpath
=
"/"
.
join
([
PLUGINDIR
,
name
])
if
os
.
path
.
isdir
(
plugpath
):
p
=
getPlugin
(
name
,
core
)
self
.
plugreg
[
name
]
=
p
p
.
initialize
(
ConvenienceCaller
(
lambda
c
:
self
.
_plugincback
(
name
,
c
)),
PluginLogger
(
name
))
def
_plugincback
(
self
,
who
,
cmd
,
*
args
,
**
kwargs
):
"""
The callback that try to find an appropriate method exported
to a higher level object by the ConvenienceCaller metaclass.
This isn't intended to be called by the user directly, instead pass it
to the instance of the higher level object initialization or by
setting it using the abstraction of the ConvenienceCaller metaclass
"""
try
:
try
:
f
=
getattr
(
self
,
who
+
'_on_'
+
cmd
)
except
:
try
:
f
=
getattr
(
self
,
'on_'
+
cmd
)
except
:
f
=
self
.
core
.
cmd
if
f
and
callable
(
f
):
return
f
except
:
raise
AttributeError
(
" "
.
join
([
cmd
,
'doesn
\'
t exists'
]))
penguidom/plugins/__init__.py
0 → 100644
View file @
981f368f
###########################################################################
# Copyright (c) 2018- Franco (nextime) Lanza <franco@unixmedia.it>
#
# Penguidom System Controller Daemon "penguidomd"
#
# This file is part of penguidomd.
#
# penguidomd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# This is a twisted plugin directory
try
:
from
twisted.plugin
import
pluginPackagePaths
__path__
.
extend
(
pluginPackagePaths
(
__name__
))
except
ImportError
:
# Twisted 2.5 doesn't include pluginPackagePaths
import
sys
,
os
__path__
.
extend
([
os
.
path
.
abspath
(
os
.
path
.
join
(
x
,
'plugins'
))
for
x
in
sys
.
path
])
__all__
=
[]
penguidom/plugins/paradox/__init__.py
0 → 100644
View file @
981f368f
from
paradox
import
Paradox
plugin
=
Paradox
()
penguidom/plugins/paradox/paradox.py
View file @
981f368f
This diff is collapsed.
Click to expand it.
penguidomd
View file @
981f368f
...
...
@@ -97,6 +97,8 @@ if __name__ == "__main__":
logdict
=
{
"corelog"
:
{
"file"
:
"penguidom.log"
,
"name"
:[(
"Core"
,
"general"
)]},
"pluginslog"
:
{
"file"
:
"plugins.log"
,
"name"
:[(
"Plugins"
,
"plugins"
)]},
"protocollog"
:
{
"file"
:
"ikap.log"
,
"name"
:
[(
"IKAProtocol"
,
"ikap"
),(
"IKAPServer"
,
"ikap"
),(
"DMDomain"
,
"ikap"
)]},
...
...
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