Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
weboob
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
182
Issues
182
List
Boards
Labels
Milestones
Merge Requests
53
Merge Requests
53
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
weboob
weboob
Commits
fbf91d70
Commit
fbf91d70
authored
Feb 19, 2019
by
JEAN Sébastien
Committed by
Laurent Bachelier
Feb 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: Boilerplate refactoring for extended usage
parent
db462916
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
171 additions
and
106 deletions
+171
-106
tools/boilerplate/__init__.py
tools/boilerplate/__init__.py
+0
-0
tools/boilerplate/boilerplate.py
tools/boilerplate/boilerplate.py
+73
-0
tools/boilerplate/boilerplate_data/base_browser.pyt
tools/boilerplate/boilerplate_data/base_browser.pyt
+1
-1
tools/boilerplate/boilerplate_data/base_module.pyt
tools/boilerplate/boilerplate_data/base_module.pyt
+1
-1
tools/boilerplate/boilerplate_data/base_pages.pyt
tools/boilerplate/boilerplate_data/base_pages.pyt
+1
-1
tools/boilerplate/boilerplate_data/base_test.pyt
tools/boilerplate/boilerplate_data/base_test.pyt
+1
-1
tools/boilerplate/boilerplate_data/cap_module.pyt
tools/boilerplate/boilerplate_data/cap_module.pyt
+1
-1
tools/boilerplate/boilerplate_data/comic_module.pyt
tools/boilerplate/boilerplate_data/comic_module.pyt
+1
-1
tools/boilerplate/boilerplate_data/comic_test.pyt
tools/boilerplate/boilerplate_data/comic_test.pyt
+1
-1
tools/boilerplate/boilerplate_data/init.pyt
tools/boilerplate/boilerplate_data/init.pyt
+1
-1
tools/boilerplate/boilerplate_data/layout.pyt
tools/boilerplate/boilerplate_data/layout.pyt
+0
-0
tools/boilerplate/boilerplate_data/recipes.py
tools/boilerplate/boilerplate_data/recipes.py
+6
-98
tools/boilerplate/recipe.py
tools/boilerplate/recipe.py
+84
-0
No files found.
tools/boilerplate/__init__.py
0 → 100644
View file @
fbf91d70
tools/boilerplate/boilerplate.py
0 → 100755
View file @
fbf91d70
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright(C) 2013-2019 Laurent Bachelier, Sébastien Jean
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
print_function
import
argparse
import
inspect
import
subprocess
import
os
import
sys
from
importlib
import
import_module
BOILERPLATE_PATH
=
os
.
getenv
(
'BOILERPLATE_PATH'
,
os
.
path
.
realpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'boilerplate_data'
)))
sys
.
path
.
append
(
os
.
path
.
dirname
(
__file__
))
sys
.
path
.
append
(
BOILERPLATE_PATH
)
def
u8
(
s
):
if
isinstance
(
s
,
bytes
):
return
s
.
decode
(
'utf-8'
)
return
s
def
gitconfig
(
entry
):
return
u8
(
subprocess
.
check_output
(
'git config -z --get
%
s'
%
entry
,
shell
=
True
)[:
-
1
])
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-a'
,
'--author'
,
default
=
gitconfig
(
'user.name'
),
type
=
u8
)
parser
.
add_argument
(
'-e'
,
'--email'
,
default
=
gitconfig
(
'user.email'
),
type
=
u8
)
subparsers
=
parser
.
add_subparsers
()
recipes_module
=
import_module
(
'recipes'
,
package
=
'boilerplate_data'
)
for
k
,
v
in
recipes_module
.
__dict__
.
items
():
if
inspect
.
isclass
(
v
)
and
not
k
.
startswith
(
'_'
):
v
.
configure_subparser
(
subparsers
)
args
=
parser
.
parse_args
()
recipe
=
args
.
recipe
(
args
)
recipe
.
generate
()
if
__name__
==
'__main__'
:
main
()
tools/boilerplate
_data/base_browser.py
→
tools/boilerplate
/boilerplate_data/base_browser.pyt
View file @
fbf91d70
<%
inherit
file
=
"layout.py"
/>
<%inherit file="layout.py
t
"/>
from weboob.browser import ${'LoginBrowser, need_login' if r.login else 'PagesBrowser'}, URL
from .pages import Page1, Page2
...
...
tools/boilerplate
_data/base_module.py
→
tools/boilerplate
/boilerplate_data/base_module.pyt
View file @
fbf91d70
<%
inherit
file
=
"layout.py"
/>
<%inherit file="layout.py
t
"/>
from weboob.tools.backend import Module
from .browser import ${r.classname}Browser
...
...
tools/boilerplate
_data/base_pages.py
→
tools/boilerplate
/boilerplate_data/base_pages.pyt
View file @
fbf91d70
<%
inherit
file
=
"layout.py"
/>
<%inherit file="layout.py
t
"/>
from weboob.browser.pages import HTMLPage
...
...
tools/boilerplate
_data/base_test.py
→
tools/boilerplate
/boilerplate_data/base_test.pyt
View file @
fbf91d70
<%
inherit
file
=
"layout.py"
/>
<%inherit file="layout.py
t
"/>
from weboob.tools.test import BackendTest
...
...
tools/boilerplate
_data/cap_module.py
→
tools/boilerplate
/boilerplate_data/cap_module.pyt
View file @
fbf91d70
<%
inherit
file
=
"layout.py"
/>
<%inherit file="layout.py
t
"/>
from weboob.tools.backend import Module${', BackendConfig' if r.login else ''}
% if login:
from weboob.tools.value import Value, ValueBackendPassword
...
...
tools/boilerplate
_data/comic_module.py
→
tools/boilerplate
/boilerplate_data/comic_module.pyt
View file @
fbf91d70
<%
inherit
file
=
"layout.py"
/>
<%inherit file="layout.py
t
"/>
from weboob.tools.capabilities.gallery.genericcomicreader import GenericComicReaderModule, DisplayPage
...
...
tools/boilerplate
_data/comic_test.py
→
tools/boilerplate
/boilerplate_data/comic_test.pyt
View file @
fbf91d70
<%
inherit
file
=
"layout.py"
/>
<%inherit file="layout.py
t
"/>
from weboob.tools.capabilities.gallery.genericcomicreadertest import GenericComicReaderTest
...
...
tools/boilerplate
_data/init.py
→
tools/boilerplate
/boilerplate_data/init.pyt
View file @
fbf91d70
<%
inherit
file
=
"layout.py"
/>
<%inherit file="layout.py
t
"/>
from .module import ${r.classname}Module
...
...
tools/boilerplate
_data/layout.py
→
tools/boilerplate
/boilerplate_data/layout.pyt
View file @
fbf91d70
File moved
tools/boilerplate.py
→
tools/boilerplate
/boilerplate_data/recipes
.py
100755 → 100644
View file @
fbf91d70
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright(C) 2013
Laurent Bachelier
# Copyright(C) 2013
-2019 Laurent Bachelier, Sébastien Jean
#
# This file is part of weboob.
#
...
...
@@ -20,82 +20,13 @@
from
__future__
import
print_function
import
argparse
import
subprocess
import
datetime
import
importlib
import
os
import
sys
import
codecs
from
mako.lookup
import
TemplateLookup
MODULE_PATH
=
os
.
getenv
(
'MODULE_PATH'
,
os
.
path
.
realpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'../modules'
)))
TEMPLATE_PATH
=
os
.
getenv
(
'TEMPLATE_PATH'
,
os
.
path
.
realpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'boilerplate_data'
)))
VERSION
=
'1.5'
from
recipe
import
_Recipe
TEMPLATES
=
TemplateLookup
(
directories
=
[
TEMPLATE_PATH
])
def
u8
(
s
):
if
isinstance
(
s
,
bytes
):
return
s
.
decode
(
'utf-8'
)
return
s
def
gitconfig
(
entry
):
return
u8
(
subprocess
.
check_output
(
'git config -z --get
%
s'
%
entry
,
shell
=
True
)[:
-
1
])
def
write
(
target
,
contents
):
if
not
os
.
path
.
isdir
(
os
.
path
.
dirname
(
target
)):
os
.
makedirs
(
os
.
path
.
dirname
(
target
))
if
os
.
path
.
exists
(
target
):
print
(
"
%
s already exists."
%
target
,
file
=
sys
.
stderr
)
sys
.
exit
(
4
)
with
codecs
.
open
(
target
,
mode
=
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
contents
)
print
(
'Created
%
s'
%
target
)
class
Recipe
(
object
):
@
classmethod
def
configure_subparser
(
cls
,
subparsers
):
subparser
=
subparsers
.
add_parser
(
cls
.
NAME
)
subparser
.
add_argument
(
'name'
,
help
=
'Module name'
)
subparser
.
set_defaults
(
recipe
=
cls
)
return
subparser
def
__init__
(
self
,
args
):
self
.
name
=
args
.
name
.
lower
()
.
replace
(
' '
,
''
)
self
.
classname
=
args
.
name
.
title
()
.
replace
(
' '
,
''
)
self
.
year
=
datetime
.
date
.
today
()
.
year
self
.
author
=
args
.
author
self
.
email
=
args
.
email
self
.
version
=
VERSION
self
.
login
=
False
def
write
(
self
,
filename
,
contents
):
return
write
(
os
.
path
.
join
(
MODULE_PATH
,
self
.
name
,
filename
),
contents
)
def
template
(
self
,
name
,
**
kwargs
):
if
'.'
not
in
name
:
name
+=
'.py'
return
TEMPLATES
.
get_template
(
name
)
\
.
render
(
r
=
self
,
# workaround, as it's also a mako directive
coding
=
'# -*- coding: utf-8 -*-'
,
login
=
self
.
login
,
**
kwargs
)
def
generate
(
self
):
raise
NotImplementedError
()
class
BaseRecipe
(
Recipe
):
class
BaseRecipe
(
_Recipe
):
NAME
=
'base'
def
generate
(
self
):
...
...
@@ -106,7 +37,7 @@ def generate(self):
self
.
write
(
'test.py'
,
self
.
template
(
'base_test'
))
class
CapRecipe
(
Recipe
):
class
CapRecipe
(
_
Recipe
):
NAME
=
'cap'
def
__init__
(
self
,
args
):
...
...
@@ -185,7 +116,7 @@ def generate(self):
self
.
write
(
'test.py'
,
self
.
template
(
'base_test'
))
class
ComicRecipe
(
Recipe
):
class
ComicRecipe
(
_
Recipe
):
NAME
=
'comic'
def
generate
(
self
):
...
...
@@ -193,7 +124,7 @@ def generate(self):
self
.
write
(
'module.py'
,
self
.
template
(
'comic_module'
))
class
ComicTestRecipe
(
Recipe
):
class
ComicTestRecipe
(
_
Recipe
):
NAME
=
'comic.test'
@
classmethod
...
...
@@ -208,26 +139,3 @@ def __init__(self, args):
def
generate
(
self
):
self
.
write
(
'test.py'
,
self
.
template
(
'comic_test'
))
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-a'
,
'--author'
,
default
=
gitconfig
(
'user.name'
),
type
=
u8
)
parser
.
add_argument
(
'-e'
,
'--email'
,
default
=
gitconfig
(
'user.email'
),
type
=
u8
)
subparsers
=
parser
.
add_subparsers
()
recipes
=
[
BaseRecipe
,
ComicRecipe
,
ComicTestRecipe
,
CapRecipe
]
for
recipe
in
recipes
:
recipe
.
configure_subparser
(
subparsers
)
args
=
parser
.
parse_args
()
recipe
=
args
.
recipe
(
args
)
recipe
.
generate
()
if
__name__
==
'__main__'
:
main
()
tools/boilerplate/recipe.py
0 → 100644
View file @
fbf91d70
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Laurent Bachelier
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
print_function
import
os
import
datetime
import
sys
import
codecs
from
mako.lookup
import
TemplateLookup
from
weboob
import
__version__
WEBOOB_MODULES
=
os
.
getenv
(
'WEBOOB_MODULES'
,
os
.
path
.
realpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'../../modules'
)))
BOILERPLATE_PATH
=
os
.
getenv
(
'BOILERPLATE_PATH'
,
os
.
path
.
realpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'boilerplate_data'
)))
TEMPLATES
=
TemplateLookup
(
directories
=
[
BOILERPLATE_PATH
])
def
write
(
target
,
contents
):
if
not
os
.
path
.
isdir
(
os
.
path
.
dirname
(
target
)):
os
.
makedirs
(
os
.
path
.
dirname
(
target
))
if
os
.
path
.
exists
(
target
):
print
(
"
%
s already exists."
%
target
,
file
=
sys
.
stderr
)
sys
.
exit
(
4
)
with
codecs
.
open
(
target
,
mode
=
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
contents
)
print
(
'Created
%
s'
%
target
)
class
_Recipe
(
object
):
@
classmethod
def
configure_subparser
(
cls
,
subparsers
):
subparser
=
subparsers
.
add_parser
(
cls
.
NAME
)
subparser
.
add_argument
(
'name'
,
help
=
'Module name'
)
subparser
.
set_defaults
(
recipe
=
cls
)
return
subparser
def
__init__
(
self
,
args
):
self
.
name
=
args
.
name
.
lower
()
.
replace
(
' '
,
''
)
self
.
classname
=
args
.
name
.
title
()
.
replace
(
' '
,
''
)
self
.
year
=
datetime
.
date
.
today
()
.
year
self
.
author
=
args
.
author
self
.
email
=
args
.
email
self
.
version
=
__version__
self
.
login
=
False
def
write
(
self
,
filename
,
contents
):
return
write
(
os
.
path
.
join
(
WEBOOB_MODULES
,
self
.
name
,
filename
),
contents
)
def
template
(
self
,
name
,
**
kwargs
):
if
'.'
not
in
name
:
name
+=
'.pyt'
return
TEMPLATES
.
get_template
(
name
)
\
.
render
(
r
=
self
,
# workaround, as it's also a mako directive
coding
=
'# -*- coding: utf-8 -*-'
,
login
=
self
.
login
,
**
kwargs
)
def
generate
(
self
):
raise
NotImplementedError
()
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