mirror of
https://github.com/2martens/uni.git
synced 2026-05-07 11:56:26 +02:00
[OE-Drucken] Moved code to repo frmwrk123/oeprint
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -1,33 +0,0 @@
|
||||
"""config.py: Provides functions to read the config"""
|
||||
|
||||
__author__ = 'Jim Martens'
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class Config:
|
||||
def __init__(self, config_file):
|
||||
self.config_file = config_file
|
||||
self.config_data = self.load_json_file()
|
||||
|
||||
def load_build(self, build):
|
||||
"""
|
||||
Loads the data of a particular build or an empty object if no such build exists
|
||||
:type build: str
|
||||
:rtype: dict
|
||||
"""
|
||||
if build in self.config_data:
|
||||
build_data = self.config_data[build]
|
||||
else:
|
||||
build_data = {}
|
||||
return build_data
|
||||
|
||||
def load_json_file(self):
|
||||
"""
|
||||
Loads the JSON configuration file
|
||||
:type self: config.Config
|
||||
:rtype : dict
|
||||
"""
|
||||
file = open(self.config_file, 'r', encoding='utf-8')
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
@ -1,12 +0,0 @@
|
||||
{
|
||||
"infodesk": {
|
||||
"files": [
|
||||
{
|
||||
"identifier": "test",
|
||||
"prints": 1,
|
||||
"options": "sides=one-sided"
|
||||
}
|
||||
],
|
||||
"builds": []
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
"""file.py: Provides functionality to manage printable files."""
|
||||
|
||||
__author__ = 'Jim Martens'
|
||||
|
||||
|
||||
def get_file_path(year, directory, identifier):
|
||||
"""
|
||||
Returns the file path for the given identifier.
|
||||
:type year: str
|
||||
:type directory: str
|
||||
:type identifier: str
|
||||
:rtype: str
|
||||
"""
|
||||
path = directory + '/' + identifier + '/'
|
||||
version_file = open(path + 'version.txt')
|
||||
current_version = version_file.readline().strip()
|
||||
return path + year + '_' + identifier + '_V' + current_version + '.pdf'
|
||||
|
||||
|
||||
def insert_file_paths(year, directory, files):
|
||||
"""
|
||||
Manipulates the files list and adds a key named path to each object in the list.
|
||||
:type year: str
|
||||
:type directory: str
|
||||
:type files: list
|
||||
:rtype: list
|
||||
"""
|
||||
file_configs = []
|
||||
for file_config in files:
|
||||
file_config['path'] = get_file_path(year, directory, file_config['identifier'])
|
||||
file_configs.append(file_config)
|
||||
|
||||
return file_configs
|
||||
@ -1,33 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
"""oeprint.py: The main file of the print tool"""
|
||||
|
||||
__author__ = 'Jim Martens'
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from config import Config
|
||||
from file import *
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function for oeprint"""
|
||||
year = '2015'
|
||||
|
||||
parser = argparse.ArgumentParser(description='Printing tool for Orientation Unit')
|
||||
parser.add_argument('build', metavar='build', help='the identifier of the build')
|
||||
parser.add_argument('prints', metavar='numberOfPrints', type=int, help='how often the build is printed')
|
||||
parser.add_argument('--printer', dest='printer', help='a valid printer name like d116_sw', default='d116_sw')
|
||||
arguments = parser.parse_args()
|
||||
config = Config('configuration/config.json')
|
||||
build_data = config.load_build(arguments.build)
|
||||
if build_data:
|
||||
build_data['files'] = insert_file_paths(year, 'files', build_data['files'])
|
||||
print(build_data)
|
||||
else:
|
||||
print('Invalid build', file=sys.stderr)
|
||||
# TODO add actual functionality
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user