Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
Hdlmake
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
15
Issues
15
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Hdlmake
Commits
4dabda15
Commit
4dabda15
authored
Oct 04, 2019
by
Tristan Gingold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring.
parent
8a765caa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
35 deletions
+25
-35
configparser.py
hdlmake/manifest_parser/configparser.py
+3
-5
manifestparser.py
hdlmake/manifest_parser/manifestparser.py
+0
-26
module.py
hdlmake/module/module.py
+22
-4
No files found.
hdlmake/manifest_parser/configparser.py
View file @
4dabda15
...
...
@@ -228,10 +228,6 @@ types:[<type 'int'>]
Note that this is only allowed when the option's value is a dict!!"""
self
[
name
]
.
add_key
(
key
)
def
add_config_file
(
self
,
config_file
):
"""Add the Manifest to be processed by the parser"""
self
.
config_file
=
config_file
def
add_prefix_code
(
self
,
code
):
"""Add the arbitrary Python to be executed just before the Manifest"""
self
.
prefix_code
+=
code
+
'
\n
'
...
...
@@ -282,11 +278,13 @@ types:[<type 'int'>]
assert
self
.
config_file
is
not
None
return
open
(
self
.
config_file
,
"r"
)
.
read
()
def
parse
(
self
,
extra_context
=
None
):
def
parse
(
self
,
config_file
,
extra_context
=
None
):
"""Parse the stored manifest plus arbitrary code. Return a dictionnary
of variables defined in the manifest."""
assert
isinstance
(
extra_context
,
dict
)
or
extra_context
is
None
self
.
config_file
=
config_file
# These HDLMake keys must not be inherited from parent module
key_purge_list
=
[
"modules"
,
"files"
,
"include_dirs"
,
"inc_makefiles"
,
"library"
]
...
...
hdlmake/manifest_parser/manifestparser.py
View file @
4dabda15
...
...
@@ -267,32 +267,6 @@ class ManifestParser(ConfigParser):
help
=
option
[
"help"
],
type
=
option
[
"type"
])
def
add_manifest
(
self
,
path
):
"""Add to configuration the Manifest at directory (path) if exists"""
def
_search_for_manifest
(
path
):
"""
Look for manifest in the given folder and create a Manifest object
"""
logging
.
debug
(
"Looking for manifest in "
+
path
)
dir_files
=
os
.
listdir
(
path
)
if
"manifest.py"
in
dir_files
and
"Manifest.py"
in
dir_files
:
raise
Exception
(
"Both manifest.py and Manifest.py"
+
"found in the module directory:
%
s"
,
path
)
for
filename
in
dir_files
:
if
filename
==
"manifest.py"
or
filename
==
"Manifest.py"
:
if
not
os
.
path
.
isdir
(
filename
):
logging
.
debug
(
"Found manifest for module
%
s:
%
s"
,
path
,
filename
)
return
os
.
path
.
join
(
path
,
filename
)
return
None
manifest
=
_search_for_manifest
(
path
)
if
manifest
is
None
:
raise
Exception
(
"No manifest found in path: {}"
.
format
(
path
))
logging
.
debug
(
"Parse manifest in:
%
s"
,
manifest
)
self
.
add_config_file
(
manifest
)
def
print_help
(
self
):
"""Print the help for the Manifest parser object"""
self
.
help
()
hdlmake/module/module.py
View file @
4dabda15
...
...
@@ -73,6 +73,24 @@ class Module(ModuleContent):
command_tmp
=
shell
.
rmdir_command
()
+
" "
+
self
.
path
shell
.
run
(
command_tmp
)
def
_search_for_manifest
(
self
):
"""Look for manifest in the given folder and create a Manifest object
"""
logging
.
debug
(
"Looking for manifest in "
+
self
.
path
)
dir_files
=
os
.
listdir
(
self
.
path
)
if
"manifest.py"
in
dir_files
and
"Manifest.py"
in
dir_files
:
raise
Exception
(
"Both manifest.py and Manifest.py"
+
"found in the module directory:
%
s"
,
self
.
path
)
for
filename
in
dir_files
:
if
filename
==
"manifest.py"
or
filename
==
"Manifest.py"
:
if
not
os
.
path
.
isdir
(
filename
):
logging
.
debug
(
"Found manifest for module
%
s:
%
s"
,
self
.
path
,
filename
)
return
os
.
path
.
join
(
self
.
path
,
filename
)
raise
Exception
(
"No manifest found in path: {}"
.
format
(
self
.
path
))
def
parse_manifest
(
self
):
"""
Create a dictionary from the module Manifest.py and assign it
...
...
@@ -95,6 +113,9 @@ class Module(ModuleContent):
return
assert
self
.
path
is
not
None
filename
=
self
.
_search_for_manifest
()
logging
.
debug
(
"Parse manifest in:
%
s"
,
filename
)
logging
.
debug
(
"""
***********************************************************
PARSE START:
%
s
...
...
@@ -105,9 +126,6 @@ PARSE START: %s
manifest_parser
.
add_prefix_code
(
self
.
pool
.
options
.
prefix_code
)
manifest_parser
.
add_suffix_code
(
self
.
pool
.
options
.
suffix_code
)
# Look for the Manifest.py file
manifest_parser
.
add_manifest
(
self
.
path
)
# Parse and extract variables from it.
if
self
.
parent
is
None
:
extra_context
=
{}
...
...
@@ -118,7 +136,7 @@ PARSE START: %s
# The parse method is where most of the parser action takes place!
opt_map
=
None
try
:
opt_map
=
manifest_parser
.
parse
(
extra_context
=
extra_context
)
opt_map
=
manifest_parser
.
parse
(
config_file
=
filename
,
extra_context
=
extra_context
)
except
NameError
as
name_error
:
raise
Exception
(
"Error while parsing {0}:
\n
{1}: {2}."
.
format
(
...
...
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