- leichter Umbau der Shellskripte. Extrakt des Fonts getrennt von test des Fonts
This commit is contained in:
+31
-2
@@ -4,6 +4,9 @@
|
||||
from django.utils.encoding import smart_unicode
|
||||
from django.template.defaultfilters import slugify
|
||||
import csv
|
||||
import ConfigParser
|
||||
import os.path
|
||||
import re
|
||||
|
||||
def csv_open(csvfile, dialect=None):
|
||||
fh = open(csvfile, 'rb')
|
||||
@@ -43,13 +46,13 @@ class CSVImport(object):
|
||||
self.firstrow = self.rows[0]
|
||||
self.field_definition = []
|
||||
for i, field in enumerate(self.rows[0]):
|
||||
if not field:
|
||||
field = 'column_%d' % i
|
||||
if translate:
|
||||
if field in translate:
|
||||
print field + ' -> '+ translate[field]
|
||||
field = translate[field]
|
||||
field = slugify(field.strip()).replace('-', '_')
|
||||
if not field:
|
||||
field = 'column_%d' % i
|
||||
self.field_definition.append(field)
|
||||
|
||||
def __getitem__(self, key):
|
||||
@@ -65,4 +68,30 @@ class CSVImport(object):
|
||||
def firstrow(self):
|
||||
return self.firstrow
|
||||
|
||||
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)
|
||||
|
||||
trans = dict(config.items(sec_name))
|
||||
return dict([[v,k] for k,v in trans.items()])
|
||||
|
||||
def CompleteEnding(path, newext):
|
||||
''' Fügt die gegebene File Extension an den Filename/Pfad
|
||||
'''
|
||||
if not path: raise Csv2CouchError('no path given')
|
||||
path, ext = os.path.splitext(path)
|
||||
if not re.match(newext, ext):
|
||||
path = path +'.'+newext
|
||||
return path
|
||||
|
||||
def RemoveEnding(path, oldext):
|
||||
''' entfernt die File Extension vom Filename/Pfad
|
||||
'''
|
||||
newpath, ext = os.path.splitext(path)
|
||||
if not re.match(oldext, ext):
|
||||
path = newpath
|
||||
return path
|
||||
|
||||
# vim: set tw=75 ft=python ts=4 sw=4:
|
||||
|
||||
Reference in New Issue
Block a user