Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
biseau
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
8
Issues
8
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
BOURNEUF Lucas
biseau
Commits
7b9a6c85
Commit
7b9a6c85
authored
Nov 06, 2018
by
Lucas Bourneuf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nb_model argument + fix multiple image generation
parent
9dc74f26
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
15 deletions
+30
-15
biseau/__init__.py
biseau/__init__.py
+1
-1
biseau/__main__.py
biseau/__main__.py
+13
-4
biseau/core.py
biseau/core.py
+16
-10
No files found.
biseau/__init__.py
View file @
7b9a6c85
from
.module_loader
import
Script
from
.core
import
single_image_from_filenames
,
gif_from_filenames
from
.core
import
single_image_from_filenames
,
multiple_images_from_filenames
,
gif_from_filenames
__version__
=
'0.0.5.dev0'
biseau/__main__.py
View file @
7b9a6c85
...
...
@@ -9,6 +9,7 @@ import os
import
argparse
import
itertools
from
.
import
core
from
.
import
__version__
def
parse_cli
(
args
:
iter
=
None
)
->
dict
:
...
...
@@ -18,13 +19,15 @@ def parse_cli(args:iter=None) -> dict:
parser
.
add_argument
(
'infiles'
,
type
=
str
,
nargs
=
'*'
,
metavar
=
'MODULE'
,
default
=
[],
help
=
'files containing ASP or Python code'
)
parser
.
add_argument
(
'--outfile'
,
'-o'
,
type
=
str
,
default
=
'out.png'
,
help
=
"output file. Will be overwritten with png data. Can be templated with '{
model_number
}'"
)
help
=
"output file. Will be overwritten with png data. Can be templated with '{}'"
)
parser
.
add_argument
(
'--dotfile'
,
'-d'
,
type
=
str
,
default
=
None
,
help
=
"output file. Will be overwritten with dot data. Can be templated with '{
model_number
}'"
)
help
=
"output file. Will be overwritten with dot data. Can be templated with '{}'"
)
parser
.
add_argument
(
'--config'
,
'-c'
,
type
=
str
,
default
=
None
,
help
=
"configuration file, specifying scripts and their options"
)
parser
.
add_argument
(
'--gif-duration'
,
'-gd'
,
type
=
int
,
default
=
500
,
help
=
"gif duration in second"
)
help
=
"gif duration in millisecond"
)
parser
.
add_argument
(
'--nb-model'
,
'-n'
,
type
=
int
,
default
=
0
,
help
=
"number of model of the final context to handle. 0 for all."
)
parser
.
add_argument
(
'-v'
,
'--verbosity'
,
action
=
'count'
,
default
=
0
)
# flags
...
...
@@ -52,12 +55,18 @@ if __name__ == '__main__':
dotfile_template
=
args
.
dotfile
,
duration
=
args
.
gif_duration
,
verbosity
=
args
.
verbosity
,
nb_model
=
args
.
nb_model
,
)
else
:
core
.
single_image_from_filenames
(
if
args
.
outfile
and
'{}'
in
args
.
outfile
:
builder
=
core
.
multiple_images_from_filenames
else
:
builder
=
core
.
single_image_from_filenames
builder
(
all_infiles
,
dotfile
=
args
.
dotfile
,
outfile
=
args
.
outfile
,
return_image
=
False
,
verbosity
=
args
.
verbosity
,
nb_model
=
args
.
nb_model
,
)
biseau/core.py
View file @
7b9a6c85
...
...
@@ -26,17 +26,21 @@ EXT_TO_TYPE = utils.reverse_dict({
LOADABLE
=
{
'Python'
,
'ASP'
,
'json/ASP'
}
def
single_image_from_filenames
(
fnames
:[
str
],
outfile
:
str
=
None
,
dotfile
:
str
=
None
,
return_image
:
bool
=
True
,
verbosity
:
int
=
0
)
->
Image
or
None
:
def
single_image_from_filenames
(
fnames
:[
str
],
outfile
:
str
=
None
,
dotfile
:
str
=
None
,
nb_model
:
int
=
0
,
return_image
:
bool
=
True
,
verbosity
:
int
=
0
)
->
Image
or
None
:
pipeline
=
build_pipeline
(
fnames
,
verbosity
)
final_context
=
run
(
pipeline
,
verbosity
=
verbosity
)
return
compile_to_single_image
(
final_context
,
outfile
=
outfile
,
dotfile
=
dotfile
,
return_image
=
return_image
,
verbosity
=
verbosity
)
return
compile_to_single_image
(
final_context
,
nb_model
=
nb_model
,
outfile
=
outfile
,
dotfile
=
dotfile
,
return_image
=
return_image
,
verbosity
=
verbosity
)
def
multiple_images_from_filenames
(
fnames
:[
str
],
outfile
:
str
=
'out-{}.png'
,
dotfile
:
str
=
None
,
nb_model
:
int
=
0
,
return_image
:
bool
=
True
,
verbosity
:
int
=
0
)
->
Image
or
None
:
pipeline
=
build_pipeline
(
fnames
,
verbosity
)
final_context
=
run
(
pipeline
,
verbosity
=
verbosity
)
return
tuple
(
compile_to_images
(
final_context
,
nb_model
=
nb_model
,
outfile_template
=
outfile
,
dotfile_template
=
dotfile
,
return_image
=
return_image
,
verbosity
=
verbosity
))
def
gif_from_filenames
(
fnames
:[
str
],
giffile
:
str
=
None
,
dotfile_template
:
str
=
None
,
duration
:
int
=
1000
,
loop
:
int
=
0
,
verbosity
:
int
=
0
)
->
bytes
or
str
:
def
gif_from_filenames
(
fnames
:[
str
],
giffile
:
str
=
None
,
dotfile_template
:
str
=
None
,
duration
:
int
=
1000
,
loop
:
int
=
0
,
nb_model
:
int
=
0
,
verbosity
:
int
=
0
)
->
bytes
or
str
:
"""Make a gif, with each ASP model as an image. Save it in outfile and dotfile_template"""
pipeline
=
build_pipeline
(
fnames
,
verbosity
)
final_context
=
run
(
pipeline
,
verbosity
=
verbosity
)
first
,
*
lasts
=
compile_to_images
(
final_context
,
dotfile_template
=
dotfile_template
,
return_image
=
True
,
verbosity
=
verbosity
)
first
,
*
lasts
=
compile_to_images
(
final_context
,
dotfile_template
=
dotfile_template
,
return_image
=
True
,
nb_model
=
nb_model
,
verbosity
=
verbosity
)
output
=
io
.
BytesIO
()
if
giffile
is
None
else
giffile
first
.
save
(
output
,
format
=
'gif'
,
append_images
=
lasts
,
duration
=
duration
,
loop
=
loop
,
save_all
=
True
)
return
output
.
getvalue
()
if
giffile
is
None
else
giffile
...
...
@@ -106,15 +110,16 @@ def run(scripts:[Script], initial_context:str='', verbosity:int=0) -> str:
return
context
def
solve_context
(
context
:
str
)
->
clyngor
.
Answers
:
return
clyngor
.
solve
(
inline
=
context
).
by_predicate
.
careful_parsing
.
int_not_parsed
def
solve_context
(
context
:
str
,
*
,
nb_model
:
int
=
0
)
->
clyngor
.
Answers
:
return
clyngor
.
solve
(
inline
=
context
,
nb_model
=
nb_model
,
options
=
'--project'
).
by_predicate
.
careful_parsing
.
int_not_parsed
def
compile_to_single_image
(
context
:
str
,
outfile
:
str
=
None
,
dotfile
:
str
=
None
,
return_image
:
bool
=
True
,
verbosity
:
int
=
0
)
->
Image
or
None
:
nb_model
:
int
=
0
,
return_image
:
bool
=
True
,
verbosity
:
int
=
0
)
->
Image
or
None
:
"Return a pillow.Image object, or write it to outfile if given"
configs
=
asp_to_dot
.
visual_config_from_asp
(
solve_context
(
context
)
solve_context
(
context
,
nb_model
=
nb_model
)
)
dot
=
dot_writer
.
one_graph_from_configs
(
configs
)
del_outfile
=
False
...
...
@@ -131,7 +136,8 @@ def compile_to_single_image(context:str, outfile:str=None, dotfile:str=None,
def
compile_to_images
(
context
:
str
,
outfile_template
:
str
=
None
,
dotfile_template
:
str
=
None
,
return_image
:
bool
=
True
,
verbosity
:
int
=
0
)
->
[
Image
]:
nb_model
:
int
=
0
,
return_image
:
bool
=
True
,
verbosity
:
int
=
0
)
->
[
Image
]:
"""Yield pillow.Image objects, and write it to outfile if given
outfile_template -- template name for png files, or None
...
...
@@ -139,7 +145,7 @@ def compile_to_images(context:str, outfile_template:str=None, dotfile_template:s
"""
configs
=
asp_to_dot
.
visual_config_from_asp
(
solve_context
(
context
)
solve_context
(
context
,
nb_model
=
nb_model
)
)
if
outfile_template
and
'{}'
not
in
outfile_template
:
raise
ValueError
(
"Outfile argument is not a valid template"
)
...
...
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