all: start using pathlib

Change-Id: I2b0d6ff8f534382913414fa9b35150d6f697acb4
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/34463
Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
This commit is contained in:
Alexander Zaft 2024-08-26 14:30:36 +02:00 committed by Markus Zolliker
parent 6c2b1ea355
commit fe0aa3d7d5
9 changed files with 29 additions and 29 deletions

View File

@ -24,10 +24,10 @@
import sys
import argparse
from os import path
from pathlib import Path
# Add import path for inplace usage
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
sys.path.insert(0, str(Path(__file__).absolute().parents[1]))
from frappy.client.interactive import init, run, clientenv, interact
@ -36,7 +36,7 @@ def parseArgv(argv):
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--include',
help='file to execute after connecting to the clients', metavar='file',
type=str, action='append', default=[])
type=Path, action='append', default=[])
parser.add_argument('-o', '--only-execute',
help='Do not go into interactive mode after executing files. \
Has no effect without --include.', action='store_true')

View File

@ -26,10 +26,10 @@ from __future__ import print_function
import sys
import argparse
from os import path
from pathlib import Path
# Add import path for inplace usage
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
sys.path.insert(0, str(Path(__file__).absolute().parents[1]))
import logging
from mlzlog import ColoredConsoleHandler

View File

@ -22,10 +22,10 @@
# *****************************************************************************
import sys
from os import path
from pathlib import Path
# Add import path for inplace usage
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
sys.path.insert(0, str(Path(__file__).absolute().parents[1]))
from frappy.client.interactive import Console
from frappy.playground import play, USAGE

View File

@ -24,10 +24,10 @@
import argparse
import sys
from os import path
from pathlib import Path
# Add import path for inplace usage
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
sys.path.insert(0, str(Path(__file__).absolute().parents[1]))
from frappy.lib import generalConfig
from frappy.logging import logger

View File

@ -34,13 +34,13 @@ Use cases, mainly for test purposes:
import sys
import argparse
from os import path
from pathlib import Path
import asyncore
import socket
import time
# Add import path for inplace usage
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
sys.path.insert(0, str(Path(__file__).absolute().parents[1]))
from frappy.lib import get_class, formatException, mkthread

View File

@ -352,7 +352,7 @@ def watch(*args, **kwds):
def close_node(online, state):
if online and state != 'shutdown':
return
return None
close_event.set()
return UnregisterCallback
@ -450,7 +450,7 @@ def run(filepath):
"__file__": filepath,
"__name__": "__main__",
})
with open(filepath, 'rb') as file:
with filepath.open('rb') as file:
# pylint: disable=exec-used
exec(compile(file.read(), filepath, 'exec'), clientenv.namespace, None)

View File

@ -21,15 +21,15 @@
# *****************************************************************************
from os import path
from pathlib import Path
from frappy.gui.qt import QColor, uic
uipath = path.dirname(__file__)
uipath = Path(__file__).parent
def loadUi(widget, uiname, subdir='ui'):
uic.loadUi(path.join(uipath, subdir, uiname), widget)
uic.loadUi(uipath / subdir / uiname, widget)
def is_light_theme(palette):

View File

@ -21,14 +21,13 @@
#
# *****************************************************************************
import os.path
from pathlib import Path
from subprocess import PIPE, Popen
__all__ = ['get_version']
RELEASE_VERSION_FILE = os.path.join(os.path.dirname(__file__),
'RELEASE-VERSION')
GIT_REPO = os.path.join(os.path.dirname(__file__), '..', '.git')
RELEASE_VERSION_FILE = Path(__file__).parent / 'RELEASE-VERSION'
GIT_REPO = (Path(__file__).parents[1] / '.git').resolve()
def translate_version(ver):
@ -49,14 +48,14 @@ def get_git_version(abbrev=4):
def read_release_version():
try:
with open(RELEASE_VERSION_FILE, encoding='utf-8') as f:
with RELEASE_VERSION_FILE.open(encoding='utf-8') as f:
return f.readline().strip()
except Exception:
return None
def write_release_version(version):
with open(RELEASE_VERSION_FILE, 'w', encoding='utf-8') as f:
with RELEASE_VERSION_FILE.open('w', encoding='utf-8') as f:
f.write(f'{version}\n')

View File

@ -23,19 +23,20 @@
# *****************************************************************************
from glob import glob
from os import listdir, path
from pathlib import Path
from setuptools import find_packages, setup
import frappy.version
# cfg-editor is currently not functional
scripts = [script for script in glob(path.join('bin', 'frappy-*'))
if not script.endswith('cfg-editor')]
scripts = [str(script) for script in Path('bin').glob('frappy-*')
if not str(script).endswith('cfg-editor')]
uidir = path.join(path.dirname(__file__), 'frappy', 'gui', 'ui')
uis = [path.join('gui', 'ui', entry) for entry in listdir(uidir)]
frappydir = Path(__file__).parent / 'frappy'
uidir = frappydir / 'gui' / 'ui'
uis = [str(f.relative_to(frappydir)) for f in uidir.iterdir()]
setup(
name='frappy-core',
@ -57,7 +58,7 @@ setup(
('/lib/systemd/system-generators', ['etc/frappy-generator']),
('/lib/systemd/system', ['etc/frappy@.service',
'etc/frappy.target',
]),
]),
('/var/log/frappy', []),
],
scripts=scripts,