Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
3912400d
Commit
3912400d
authored
1 year ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: fixing typhints
parent
6ffe6a89
No related branches found
Branches containing commit
No related tags found
Tags containing commit
4 merge requests
!100
WIP: Filling XLSX: Seems to be working.
,
!94
ENH: add framework for converting json schema into table templates
,
!93
Filling XLSX: Everything except multiple choice.
,
!92
ENH: xlsx template generator
Pipeline
#48128
passed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+1
-1
1 addition, 1 deletion
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
src/caosadvancedtools/table_json_conversion/table_generator.py
+13
-27
13 additions, 27 deletions
...aosadvancedtools/table_json_conversion/table_generator.py
with
14 additions
and
28 deletions
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+
1
−
1
View file @
3912400d
...
...
@@ -31,7 +31,7 @@ def _fill_leaves(json_doc: dict, workbook):
for
el
in
value
:
if
isinstance
(
el
,
dict
):
_fill_leaves
(
el
,
workbook
)
w
b
.
cell
(
1
,
2
,
el
)
w
orkbook
.
cell
(
1
,
2
,
el
)
def
_get_row_type_column
(
worksheet
):
...
...
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/table_json_conversion/table_generator.py
+
13
−
27
View file @
3912400d
...
...
@@ -22,13 +22,11 @@
"""
This module allows to generate template tables from JSON schemas.
"""
import
argparse
import
re
import
sys
from
abc
import
ABC
,
abstractmethod
from
argparse
import
RawTextHelpFormatter
from
enum
import
Enum
from
typing
import
Dict
,
List
,
Tuple
,
Union
from
typing
import
Dict
,
List
,
Optional
,
Tuple
,
Union
from
openpyxl
import
Workbook
from
openpyxl.workbook.child
import
INVALID_TITLE_REGEX
...
...
@@ -52,7 +50,7 @@ class TableTemplateGenerator(ABC):
pass
@abstractmethod
def
generate
(
self
,
schema
:
dict
,
foreign_keys
:
dict
):
def
generate
(
self
,
schema
:
dict
,
foreign_keys
:
dict
,
filepath
:
str
):
"""
generates a sheet definition from a given JSON schema
Parameters:
...
...
@@ -73,8 +71,8 @@ class TableTemplateGenerator(ABC):
"""
pass
def
_generate_sheets_from_schema
(
self
,
schema
:
dict
,
foreign_keys
:
dict
=
None
)
->
Dict
[
str
,
Dict
[
str
,
list
]]:
def
_generate_sheets_from_schema
(
self
,
schema
:
dict
,
foreign_keys
:
Optional
[
dict
]
=
None
)
->
Dict
[
str
,
Dict
[
str
,
Tuple
[
ColumnType
,
Optional
[
str
],
list
]]
]
:
"""
generates a sheet definition from a given JSON schema
Parameters
...
...
@@ -104,7 +102,7 @@ class TableTemplateGenerator(ABC):
foreign_keys
=
{}
# here, we treat the top level
# sheets[sheetname][colname]= (COL_TYPE, description, [path])
sheets
:
Dict
[
str
,
d
ict
[
str
,
Tuple
[
str
,
list
]]]
=
{}
sheets
:
Dict
[
str
,
D
ict
[
str
,
Tuple
[
ColumnType
,
Optional
[
str
]
,
list
]]]
=
{}
if
"
properties
"
not
in
schema
:
raise
ValueError
(
"
Inappropriate JSON schema: The following part should contain
"
f
"
the
'
properties
'
key:
\n
{
schema
}
\n
"
)
...
...
@@ -128,10 +126,10 @@ class TableTemplateGenerator(ABC):
else
:
raise
ValueError
(
msg
)
def
_treat_schema_element
(
self
,
schema
:
dict
,
sheets
:
dict
=
None
,
path
:
list
=
None
,
foreign_keys
:
dict
=
None
,
level_in_sheet_name
:
int
=
1
,
array_paths
:
list
=
None
)
->
Dict
[
str
,
Tuple
[
str
,
str
,
list
]]:
def
_treat_schema_element
(
self
,
schema
:
dict
,
sheets
:
dict
,
path
:
list
,
foreign_keys
:
Optional
[
dict
]
=
None
,
level_in_sheet_name
:
int
=
1
,
array_paths
:
Optional
[
list
]
=
None
)
->
Dict
[
str
,
Tuple
[
ColumnType
,
Optional
[
str
]
,
list
]]:
"""
recursively transforms elements from the schema into column definitions
sheets is modified in place.
...
...
@@ -157,6 +155,8 @@ class TableTemplateGenerator(ABC):
# if this is not set, we are at top level and the top level element may always be an
# array
array_paths
=
[
path
]
if
foreign_keys
is
None
:
foreign_keys
=
{}
ctype
=
ColumnType
.
SCALAR
...
...
@@ -272,7 +272,8 @@ class XLSXTemplateGenerator(TableTemplateGenerator):
return
ordered_cols
def
_create_workbook_from_sheets_def
(
self
,
sheets
:
Dict
[
str
,
Dict
[
str
,
Tuple
[
str
,
list
]]]):
def
_create_workbook_from_sheets_def
(
self
,
sheets
:
Dict
[
str
,
Dict
[
str
,
Tuple
[
ColumnType
,
Optional
[
str
],
list
]]]):
wb
=
Workbook
()
assert
wb
.
sheetnames
==
[
"
Sheet
"
]
for
sn
,
sheetdef
in
sheets
.
items
():
...
...
@@ -322,18 +323,3 @@ class XLSXTemplateGenerator(TableTemplateGenerator):
wb
.
move_sheet
(
sn
,
index
-
wb
.
index
(
wb
[
sn
]))
return
wb
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
RawTextHelpFormatter
)
parser
.
add_argument
(
"
path
"
,
help
=
"
the subtree of files below the given path will
"
"
be considered. Use
'
/
'
for everything.
"
)
return
parser
.
parse_args
()
if
__name__
==
"
__main__
"
:
args
=
parse_args
()
sys
.
exit
(
main
(
args
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment