Skip to content

Commit 66f590a

Browse files
committed
openflow: add configure.py
It allows configuring the OCI engine, containers and tool names.
1 parent 3248478 commit 66f590a

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

openflow/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
__version__ = '0.1.0'
44

55
from openflow.openflow import Openflow
6+
from openflow.configure import ConfigureTools

openflow/configure.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#
2+
# Copyright (C) 2020-2021 Rodrigo A. Melo
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
#
17+
18+
"""openflow.configure
19+
20+
A Class to configure the OCI engine, the containers and the name of the
21+
underlying FOSS tools.
22+
"""
23+
24+
25+
# import os
26+
# from yaml import safe_load
27+
28+
29+
_DEFAULTS = {
30+
'ecppack': 'hdlc/prjtrellis',
31+
'ghdl': 'hdlc/ghdl:yosys',
32+
'icepack': 'hdlc/icestorm',
33+
'iceprog': 'hdlc/icestorm',
34+
'icetime': 'hdlc/icestorm',
35+
'nextpnr-ecp5': 'hdlc/nextpnr:ecp5',
36+
'nextpnr-ice40': 'hdlc/nextpnr:ice40',
37+
'openocd': 'hdlc/prog',
38+
'yosys': 'hdlc/ghdl:yosys',
39+
}
40+
41+
42+
class ConfigureTools:
43+
"""Configure Tools."""
44+
45+
def __init__(self):
46+
"""Class constructor."""
47+
self.configs = {}
48+
self.configs['engine'] = 'docker'
49+
self.configs['volumes'] = ['$HOME:$HOME']
50+
self.configs['work'] = '$PWD'
51+
self.configs['containers'] = {}
52+
self.configs['names'] = {}
53+
for key, value in _DEFAULTS.items():
54+
self.configs['containers'][key] = value
55+
self.configs['names'][key] = key
56+
57+
def get_command(self, tool):
58+
"""Get the command-line needed to run a tool."""
59+
oci = ''
60+
container = ''
61+
command = self.configs['names'][tool]
62+
if self.configs['engine'] in ['docker', 'podman']:
63+
oci = '{} run --rm {} {}'.format(
64+
self.configs['engine'],
65+
'-v ' + ('-v ').join(self.configs['volumes']),
66+
'-w ' + self.configs['work']
67+
)
68+
container = self.configs['containers'][tool]
69+
return '{} {} {}'.format(oci, container, command)
70+
71+
def get_tools(self):
72+
"""Returns the list of configured tools."""
73+
return sorted(list(self.configs['names'].keys()))
74+
75+
def set_engine(self, engine, volumes, work):
76+
"""Set the OCI engine."""
77+
self.configs['engine'] = engine
78+
self.configs['volumes'] = volumes
79+
self.configs['work'] = work
80+
81+
def set_container(self, tool, container):
82+
"""Set the container of the specified tool."""
83+
self.configs['containers'][tool] = container
84+
85+
def set_name(self, tool, name):
86+
"""Set the name of the specified tool."""
87+
self.configs['names'][tool] = name
88+
89+
def set_configs_from_dict(self, configs):
90+
"""Set all the configurations from a dict."""
91+
raise NotImplementedError('set_configs_from_dict')
92+
93+
def set_configs_from_yaml(self, filename):
94+
"""Set all the configurations from a YAML file."""
95+
raise NotImplementedError('set_configs_from_yaml')

0 commit comments

Comments
 (0)