Auf Python 3 portiert, Django-Abhängigkeit entfernt

- piccreate.py, utils.py: print, configparser, has_key -> in, UTF-8 I/O
- smart_str/smart_unicode entfernt, eigenes slugify() in utils.py
- configparser mit strict=False (doppelte [+] Sektion in den Font-cfgs)
- Shebangs und bin/piccreate auf python3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michael Stangl
2026-10-09 08:53:55 +02:00
co-authored by Claude Opus 5.5
parent dc8e5230e2
commit d4cb697f14
5 changed files with 47 additions and 40 deletions
+18 -10
View File
@@ -1,15 +1,23 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from django.utils.encoding import smart_unicode
from django.template.defaultfilters import slugify
import configparser
import csv
import ConfigParser
import os.path
import os.path
import re
import unicodedata
def slugify(value):
''' wandelt einen String in einen ASCII Bezeichner um (wie Djangos slugify)
'''
value = unicodedata.normalize('NFKD', str(value))
value = value.encode('ascii', 'ignore').decode('ascii')
value = re.sub(r'[^\w\s-]', '', value).strip().lower()
return re.sub(r'[-\s]+', '-', value)
def csv_open(csvfile, dialect=None):
fh = open(csvfile, 'rb')
fh = open(csvfile, 'r', encoding='utf-8', newline='')
if dialect is None:
sniffer = csv.Sniffer()
dialect = sniffer.sniff(fh.read(1024), delimiters=';,\t')
@@ -24,7 +32,7 @@ class CSVRow(object):
self.firstrow = field_refinition
for i, field in enumerate(field_refinition):
try:
setattr(self, field, smart_unicode(row[i]))
setattr(self, field, row[i])
except IndexError:
setattr(self, field, None)
@@ -50,7 +58,7 @@ class CSVImport(object):
field = 'column_%d' % i
if translate:
if field in translate:
print field + ' -> '+ translate[field]
print(field + ' -> ' + translate[field])
field = translate[field]
field = slugify(field.strip()).replace('-', '_')
self.field_definition.append(field)
@@ -71,8 +79,8 @@ class CSVImport(object):
def get_translation(cfg_path, sec_name):
""" lädt die Zuordnung zwischen einem .csv Eingabefile und den
Attributen """
config = ConfigParser.RawConfigParser()
config.read(cfg_path)
config = configparser.RawConfigParser(strict=False)
config.read(cfg_path, encoding='utf-8')
trans = dict(config.items(sec_name))
return dict([[v,k] for k,v in trans.items()])