Compare commits
29 Commits
v0.4b
...
ccc06bc5f1
| Author | SHA1 | Date | |
|---|---|---|---|
| ccc06bc5f1 | |||
| ef91f8d26a | |||
| fe75d99736 | |||
| a4e550797c | |||
| 6e83ce559d | |||
| 04a32c7bd1 | |||
| e6fb04a9e7 | |||
| b53fb27a60 | |||
| 0bbb1947ee | |||
| 7ca177f29a | |||
| 1e8867182f | |||
| a798f29b73 | |||
| 59c41cc3ba | |||
| 18566dda2c | |||
| 59f11a2f8b | |||
| dfcbef7ae4 | |||
| 0502d77c14 | |||
| b7af353ab8 | |||
| 3f5ef6c103 | |||
| 21e7a29c33 | |||
| d01afc2ab3 | |||
| 9537530a34 | |||
| c401518db5 | |||
| 22413c3fb2 | |||
| bfbd0e8c79 | |||
| af880df5b3 | |||
|
|
3624d21e90 | ||
|
|
3c1aad543e | ||
|
|
c5ee729683 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
/.DS_Store
|
/.DS_Store
|
||||||
/.project
|
/.project
|
||||||
/.pydevproject
|
/.pydevproject
|
||||||
|
/org.eclipse.core.resources.prefs
|
||||||
bananaSPLIT/build
|
bananaSPLIT/build
|
||||||
1
.settings/.gitignore
vendored
Normal file
1
.settings/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/org.eclipse.core.resources.prefs
|
||||||
1
TestFiles/README
Normal file
1
TestFiles/README
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Qui si mettono i file di test per la versione GUI di bananaSPLIT
|
||||||
121
bananaSPLIT/UserInterface/SelezioneOutput.ui
Normal file
121
bananaSPLIT/UserInterface/SelezioneOutput.ui
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>509</width>
|
||||||
|
<height>303</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>509</width>
|
||||||
|
<height>303</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="verticalLayoutWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>80</y>
|
||||||
|
<width>251</width>
|
||||||
|
<height>141</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="rad_MainbodyEFile">
|
||||||
|
<property name="text">
|
||||||
|
<string>Main body + File singoli</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="rad_File">
|
||||||
|
<property name="text">
|
||||||
|
<string>File singoli</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="rad_Mainbody">
|
||||||
|
<property name="text">
|
||||||
|
<string>Main body</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="lbl_indicazioni">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>401</width>
|
||||||
|
<height>41</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Seleziona i file che il programma ti deve fare*chiaramente da cambiare le parole</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>330</x>
|
||||||
|
<y>230</y>
|
||||||
|
<width>160</width>
|
||||||
|
<height>51</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_Indietro">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Indietro</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_Avanti">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Avanti</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
@@ -6,24 +6,24 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>697</width>
|
<width>519</width>
|
||||||
<height>454</height>
|
<height>391</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget class="QWidget" name="horizontalLayoutWidget">
|
<widget class="QWidget" name="verticalLayoutWidget">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>20</x>
|
<x>20</x>
|
||||||
<y>20</y>
|
<y>110</y>
|
||||||
<width>161</width>
|
<width>131</width>
|
||||||
<height>31</height>
|
<height>71</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="lbl_cartellasorg">
|
<widget class="QLabel" name="lbl_cartellasorg">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
@@ -36,25 +36,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="btn_cartellasorg">
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="horizontalLayoutWidget_2">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>20</x>
|
|
||||||
<y>60</y>
|
|
||||||
<width>161</width>
|
|
||||||
<height>31</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="lbl_cartelladest">
|
<widget class="QLabel" name="lbl_cartelladest">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
@@ -67,6 +48,25 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="verticalLayoutWidget_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>150</x>
|
||||||
|
<y>110</y>
|
||||||
|
<width>34</width>
|
||||||
|
<height>71</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_cartellasorg">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_cartelladest">
|
<widget class="QPushButton" name="btn_cartelladest">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -76,16 +76,86 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>80</y>
|
||||||
|
<width>491</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>180</y>
|
||||||
|
<width>421</width>
|
||||||
|
<height>80</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="chk_predefinita">
|
||||||
|
<property name="text">
|
||||||
|
<string>Rendi predefinite le cartelle</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_avanti">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>79</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>79</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Avanti</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="btn_opzioni">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>420</x>
|
||||||
|
<y>300</y>
|
||||||
|
<width>75</width>
|
||||||
|
<height>23</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Opzioni</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>697</width>
|
<width>519</width>
|
||||||
<height>21</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QMenu" name="menuBananaSplit">
|
||||||
|
<property name="title">
|
||||||
|
<string>BananaSplit</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuBananaSplit"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
0
bananaSPLIT/libbananasplit/__init__.py
Normal file
0
bananaSPLIT/libbananasplit/__init__.py
Normal file
83
bananaSPLIT/libbananasplit/libconfload.py
Normal file
83
bananaSPLIT/libbananasplit/libconfload.py
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
'''
|
||||||
|
Created on 2 nov 2019
|
||||||
|
|
||||||
|
@author: Emanuele Trabattoni
|
||||||
|
'''
|
||||||
|
import json,os,glob,copy
|
||||||
|
|
||||||
|
class bananaCONF(object):
|
||||||
|
'''
|
||||||
|
Carica e Salva file di configurazione per bananaSPLITTER
|
||||||
|
'''
|
||||||
|
def __init__(self, workdir=None, logger=None):
|
||||||
|
self.log = logger
|
||||||
|
self.fileList = None
|
||||||
|
self.workdir = None
|
||||||
|
self.inUse = None
|
||||||
|
self.settingsList = dict()
|
||||||
|
if workdir is not None:
|
||||||
|
self.workdir = workdir
|
||||||
|
os.chdir(workdir)
|
||||||
|
self.log.debug("Cerco le configurazioni in: [{}]".format(os.getcwd()))
|
||||||
|
else:
|
||||||
|
self.log.error("Non mi e' stata fornita una directory per i file di configurazione")
|
||||||
|
pass
|
||||||
|
|
||||||
|
def open(self):
|
||||||
|
self.log.info("Carico i file di configurazione")
|
||||||
|
self.fileList = glob.glob(self.workdir+"\\*.json")
|
||||||
|
if len(self.fileList) > 0:
|
||||||
|
for f in self.fileList:
|
||||||
|
try:
|
||||||
|
fp = open(f)
|
||||||
|
tf = json.load(fp)
|
||||||
|
fName = f.split("\\")[-1]
|
||||||
|
self.settingsList[fName] = copy.deepcopy(tf)
|
||||||
|
self.log.info("Caricato correttamente: {}".format(fName))
|
||||||
|
fp.close()
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
self.log.error("Impossibile leggere la configurazione:{}\n \
|
||||||
|
Controlla il file a riga: {} e colonna:{}" .format(e.doc, e.lineno, e.colno))
|
||||||
|
except IOError as ee:
|
||||||
|
self.log.error("Impossibile aprire il file: {}".format(ee))
|
||||||
|
except Exception as eee:
|
||||||
|
self.log.critical("Eccezione inaspettata: {}".format(eee))
|
||||||
|
else:
|
||||||
|
self.log.error("Non ho trovato alcun file di configurazione!")
|
||||||
|
pass
|
||||||
|
|
||||||
|
def reload(self):
|
||||||
|
self.settingsList = None
|
||||||
|
self.fileList = None
|
||||||
|
self.inUse = None
|
||||||
|
self.open()
|
||||||
|
pass
|
||||||
|
|
||||||
|
def use(self, toUse):
|
||||||
|
self.inUse = toUse
|
||||||
|
pass
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
self.log.info("Salvo la configurazione: {}".format(self.inUse))
|
||||||
|
try:
|
||||||
|
os.chdir(self.workdir)
|
||||||
|
f=open(self.inUse)
|
||||||
|
json.dump(self.settingsList[self.inUse], f)
|
||||||
|
f.close()
|
||||||
|
except IOError as e:
|
||||||
|
self.log.error("Impossibile salvare il file: {} - [{}]".format(self.inUse,e))
|
||||||
|
pass
|
||||||
|
|
||||||
|
def getFiles(self):
|
||||||
|
return self.fileList
|
||||||
|
|
||||||
|
def getParams(self, k):
|
||||||
|
return self.settingsList[self.inUse][k]
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setParams(self, k, v):
|
||||||
|
self.settingsList[self.inUse][k]=dict(v)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
85
bananaSPLIT/libbananasplit/libfancylogger.py
Normal file
85
bananaSPLIT/libbananasplit/libfancylogger.py
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
'''
|
||||||
|
Created on 2 nov 2019
|
||||||
|
|
||||||
|
@author: Emanuele Trabattoni
|
||||||
|
'''
|
||||||
|
import sys, os
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import colorama
|
||||||
|
|
||||||
|
class fancyLogger(object):
|
||||||
|
'''
|
||||||
|
Colorizza il logger di python, per un' esperienza stile willy wonka
|
||||||
|
'''
|
||||||
|
def __init__(self, name="Logger", consoleLog=True, fileLog=True):
|
||||||
|
settings = json.load(open(os.getcwd()+r"\libbananasplit\testEN.json"))["logger"]
|
||||||
|
colorama.init(convert=True)
|
||||||
|
self.LRED = colorama.Fore.LIGHTRED_EX
|
||||||
|
self.RED = colorama.Fore.RED
|
||||||
|
self.LYELLOW = colorama.Fore.LIGHTYELLOW_EX
|
||||||
|
self.YELLOW = colorama.Fore.YELLOW
|
||||||
|
self.LBLUE = colorama.Fore.LIGHTBLUE_EX
|
||||||
|
self.BLUE = colorama.Fore.BLUE
|
||||||
|
self.LGREEN = colorama.Fore.LIGHTGREEN_EX
|
||||||
|
self.LGREEN = colorama.Fore.GREEN
|
||||||
|
self.WHITE = colorama.Fore.LIGHTWHITE_EX
|
||||||
|
self.RST = colorama.Style.RESET_ALL
|
||||||
|
|
||||||
|
# Setup Logger
|
||||||
|
self.LOGGER = logging.getLogger(name)
|
||||||
|
self.LOGGER.setLevel(logging.DEBUG)
|
||||||
|
self.LOGGER.propagate = False
|
||||||
|
FORMATTER = logging.Formatter((settings["logFormat"]), (settings["logTimeFormat"]))
|
||||||
|
if fileLog:
|
||||||
|
# File Logging
|
||||||
|
fh = logging.FileHandler((settings["logFile"]))
|
||||||
|
fh.setLevel(logging.DEBUG)
|
||||||
|
fh.setFormatter(FORMATTER)
|
||||||
|
self.LOGGER.addHandler(fh)
|
||||||
|
if consoleLog:
|
||||||
|
# Console Logging
|
||||||
|
cl= logging.StreamHandler(sys.stdout)
|
||||||
|
cl.setLevel(logging.DEBUG)
|
||||||
|
cl.setFormatter(FORMATTER)
|
||||||
|
self.LOGGER.addHandler(cl)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def debug(self, msg="Undefined Debug"):
|
||||||
|
print(self.LBLUE, end='')
|
||||||
|
self.LOGGER.debug(msg)
|
||||||
|
print(self.RST, end='')
|
||||||
|
pass
|
||||||
|
|
||||||
|
def info(self, msg="Undefined Info"):
|
||||||
|
print(self.LGREEN, end='')
|
||||||
|
self.LOGGER.info(msg)
|
||||||
|
print(self.RST, end='')
|
||||||
|
pass
|
||||||
|
|
||||||
|
def warn(self, msg="Undefined Warning"):
|
||||||
|
print(self.LYELLOW, end='')
|
||||||
|
self.LOGGER.warning(msg)
|
||||||
|
print(self.RST, end='')
|
||||||
|
pass
|
||||||
|
|
||||||
|
def error(self, msg="Undefined Error"):
|
||||||
|
print(self.LRED, end='')
|
||||||
|
self.LOGGER.error(msg)
|
||||||
|
print(self.RST, end='')
|
||||||
|
pass
|
||||||
|
|
||||||
|
def critical(self, msg="Undefined Critical"):
|
||||||
|
print(self.RED, end='')
|
||||||
|
self.LOGGER.critical(msg)
|
||||||
|
print(self.RST, end='')
|
||||||
|
pass
|
||||||
|
|
||||||
|
def testColors(self):
|
||||||
|
self.debug("Test Debug")
|
||||||
|
self.info("Test Info")
|
||||||
|
self.warn("Test Warning")
|
||||||
|
self.error("Test Error")
|
||||||
|
self.critical("Test Critical")
|
||||||
|
pass
|
||||||
|
|
||||||
245
bananaSPLIT/libbananasplit/libsplit.py
Normal file
245
bananaSPLIT/libbananasplit/libsplit.py
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
'''
|
||||||
|
Created on 2 nov 2019
|
||||||
|
|
||||||
|
@author: Emanuele Trabattoni
|
||||||
|
'''
|
||||||
|
from libfancylogger import fancyLogger
|
||||||
|
import threading, time, parse, re, copy, slugify, os
|
||||||
|
|
||||||
|
class bananaSPLITTER(threading.Thread):
|
||||||
|
|
||||||
|
def __init__(self, fileParams=None, logger=None):
|
||||||
|
self.fileParams = fileParams
|
||||||
|
self.log = logger
|
||||||
|
self.rawFile = None
|
||||||
|
self.status = "first"
|
||||||
|
self.fileList = list()
|
||||||
|
self.bodyCounter=0
|
||||||
|
self.duplicateNumber=0
|
||||||
|
if fileParams is not None:
|
||||||
|
self.log.info("Sto operando sul file: {}..".format(self.fileParams['name']))
|
||||||
|
self.paths = self.fileParams['paths']
|
||||||
|
self.docStruct = self.fileParams['docStruct']
|
||||||
|
self.settings = self.fileParams['settings']
|
||||||
|
self.fileName = self.fileParams['name']
|
||||||
|
self.beginTime = time.time()
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.log.critical("Non e' stato fornito il nome di alcun file da splittare!")
|
||||||
|
pass
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.log.info("Nuovo SPLITTER su file: {}".format(self.fileName))
|
||||||
|
self.openFile()
|
||||||
|
self.remEmptyLines()
|
||||||
|
self.splitFile()
|
||||||
|
if self.settings['removeDuplicates']:
|
||||||
|
self.log.info("Controllo se ci sono dei duplicati..")
|
||||||
|
self.removeDuplicates()
|
||||||
|
else:
|
||||||
|
for idx, ff in enumerate(self.fileList):
|
||||||
|
ff['duplicate']=False
|
||||||
|
self.fileList[idx]=ff
|
||||||
|
print('Salto il controllo dei duplicati..')
|
||||||
|
if self.settings['saveSeparateFiles']:
|
||||||
|
self.saveSeparate()
|
||||||
|
if self.settings['saveBodyFile']:
|
||||||
|
self.saveBody()
|
||||||
|
pass
|
||||||
|
|
||||||
|
def openFile(self):
|
||||||
|
try:
|
||||||
|
self.info("Carico il contenuto..")
|
||||||
|
fp = open(self.fileParams['name'], mode='r', encoding=self.settings['encoding'])
|
||||||
|
self.rawFile = fp.readlines()
|
||||||
|
fp.close()
|
||||||
|
except IOError as e:
|
||||||
|
self.log.critical("Impossibile aprire il file: {}! [{}]".format(self.fileName,e))
|
||||||
|
raise BaseException("OpenFile")
|
||||||
|
pass
|
||||||
|
|
||||||
|
def remEmptyLines(self):
|
||||||
|
self.log.info("Elimino righe vuote e caratteri inutili..")
|
||||||
|
tempContent = []
|
||||||
|
try:
|
||||||
|
for ll in self.rawFile:
|
||||||
|
for c in self.settings['delChars']:
|
||||||
|
ll = ll.replace(c,'')
|
||||||
|
if ll not in ['\n', '\r']:
|
||||||
|
tempContent.append(ll)
|
||||||
|
self.rawFile = copy.deepcopy(tempContent)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
self.log.error("Errore inaspettato durante l'eliminazione delle righe vuote!")
|
||||||
|
raise BaseException("DelLines")
|
||||||
|
del tempContent
|
||||||
|
|
||||||
|
def splitFile(self): #porting del codice dal programma originale
|
||||||
|
self.log.info("Individuo il contenuto..")
|
||||||
|
docNumber = 0
|
||||||
|
docSkipped = 0
|
||||||
|
docDate = {}
|
||||||
|
prevLine = ''
|
||||||
|
newsPaperName = ''
|
||||||
|
titleBegin = False
|
||||||
|
tempBody = list()
|
||||||
|
docSep=re.compile(self.docStruct['docSep'])
|
||||||
|
|
||||||
|
for l in self.rawFile: #per ogni linea del file
|
||||||
|
lineWords = l.lstrip().split(' ') #dividi la riga in parole
|
||||||
|
if self.status == 'first':
|
||||||
|
#prendo il numero di documento per vedere se ci sono buchi
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
nn = parse.parse("{current:d} Of {total} Documents",l.strip().capitalize()).named
|
||||||
|
if nn["current"]-docNumber==1:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if self.settings["showSkipped"]:
|
||||||
|
self.log.warning("Il conto dei documenti non torna! LexisNexis \
|
||||||
|
ne ha saltato qualcuno!\nPrecedente:{0}-Attuale:{1}".format(docNumber,nn["current"]))
|
||||||
|
docSkipped+=1
|
||||||
|
docNumber = nn["current"]
|
||||||
|
except:
|
||||||
|
pass #non segnalare eccezione se il parse fallisce
|
||||||
|
# ricerco la data
|
||||||
|
if (lineWords[self.settings['monthPosition']]).capitalize() in self.docParams['dateWords']:
|
||||||
|
try:
|
||||||
|
docDate=parse.parse(self.docParams['dateFormat'],l).named
|
||||||
|
docDate['month']=docDate['month'].lstrip().rstrip().capitalize()
|
||||||
|
docDate['month']=self.docStruct['dateWords'].index(docDate['month'])+1
|
||||||
|
title = ''
|
||||||
|
titleBegin=True
|
||||||
|
# dopo la data inizia il titolo, ma prima si cerca il nome del giornale
|
||||||
|
if self.settings['getNewsPaperName']:
|
||||||
|
try:
|
||||||
|
if prevLine.split(' ')[0].strip().isalpha():
|
||||||
|
newsPaperName = prevLine.strip()
|
||||||
|
else:
|
||||||
|
newsPaperName = self.settings['nameNotFoundStr']
|
||||||
|
except:
|
||||||
|
self.log.warning("E' successo qualcosa mentre stavo cercando il nome della pubblicazione,\
|
||||||
|
controlla i file di uscita! \n\t[{}]".format(prevLine.strip()))
|
||||||
|
else:
|
||||||
|
newsPaperName = self.settings['nameNotFoundStr']
|
||||||
|
except:
|
||||||
|
self.log.warning("Ho trovato una riga ambigua.. potrebbe essere una data ma non so: \n\t[{}]". format(l.strip('\r\n')))
|
||||||
|
pass
|
||||||
|
elif lineWords[0] in self.docStruct['headWords']:
|
||||||
|
#cambio stato e inizializzo un nuovo documento da riempire
|
||||||
|
self.status = 'head'
|
||||||
|
newDoc=dict()
|
||||||
|
newDoc['title']=title
|
||||||
|
newDoc['date']=docDate
|
||||||
|
newDoc['newsPaperName'] = newsPaperName
|
||||||
|
titleBegin=False
|
||||||
|
else:
|
||||||
|
if titleBegin:
|
||||||
|
title += l.strip().capitalize()
|
||||||
|
except IndexError:
|
||||||
|
self.log.error("Errore inaspettato, contatta il tuo sviluppatore di fiducia!")
|
||||||
|
pass
|
||||||
|
elif self.status == 'head':
|
||||||
|
tempContent = list()
|
||||||
|
if lineWords[0] not in self.docStruct['headWords']: #se la prima parola non e' tra quelle di inizio
|
||||||
|
tempBody.append(l) # vuol dire che ho trovato l'articolo e aggiungo la prima riga al contenuto del documento
|
||||||
|
self.status = 'body'
|
||||||
|
pass
|
||||||
|
elif self.status == 'body':
|
||||||
|
if not lineWords[0] in self.docStruct['tailWords']: #se la prima parola non e' tra quelle di fine
|
||||||
|
if self.settings['delLF']:
|
||||||
|
tempBody.append(l.strip('\n')) #allora sto leggendo l'articolo
|
||||||
|
else:
|
||||||
|
tempBody.append(l)
|
||||||
|
else:
|
||||||
|
self.status = 'tail'
|
||||||
|
anomaly = False
|
||||||
|
if docSep.match(l) is not None: #controlla se ci sono articoli che non hanno le parole chiave finali
|
||||||
|
self.log.warning("Ho individuato una separatore valido prima che si chiusesse l'articolo precedente, controlla i tuoi file in uscita!\n\
|
||||||
|
L'errore dovrebbe essere intorno all'articolo {} ma non sono sicuro! \n\t\t[{}]".format(docNumber, l.strip()))
|
||||||
|
self.status = 'tail'
|
||||||
|
anomaly = True
|
||||||
|
pass
|
||||||
|
elif self.status == 'tail':
|
||||||
|
if docSep.match(l) is not None or anomaly:
|
||||||
|
self.status = 'first'
|
||||||
|
anomaly = False
|
||||||
|
if self.settings['delWordBreak']:
|
||||||
|
tempContent=[ll.replace('-\n', '') for ll in tempContent]
|
||||||
|
newDoc['content']=copy.deepcopy(''.join(tempBody))
|
||||||
|
self.fileList.append(copy.deepcopy(newDoc))
|
||||||
|
tempBody=list()
|
||||||
|
self.bodyCounter +=1
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.log.critical("Stato Interno Sconosciuto")
|
||||||
|
prevLine=l #salva sempre e comunque il contenuto della linea precedente
|
||||||
|
pass
|
||||||
|
#ricerca terminata, espongo i risultati
|
||||||
|
self.log.info("Nel file ho trovato {0} articoli..".format(self.bodyCounter))
|
||||||
|
if docSkipped > 0:
|
||||||
|
self.log.warning("Attentione, LexisNexis ne ha saltati {} !!!".format(docSkipped))
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
def removeDuplicates(self):
|
||||||
|
titleList=[]
|
||||||
|
duplicateList=[]
|
||||||
|
for idx, ff in enumerate(self.fileList):
|
||||||
|
if ff['title'] not in titleList:
|
||||||
|
titleList.append(ff['title'])
|
||||||
|
ff['duplicate']=False
|
||||||
|
self.fileList[idx]=ff
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if ff['title'] not in duplicateList:
|
||||||
|
duplicateList.append(ff['title'])
|
||||||
|
if self.settings['showRemovedDuplicates']:
|
||||||
|
self.log.info("Duplicato: {}".format(ff['title'].strip()))
|
||||||
|
ff['duplicate'] = True
|
||||||
|
self.fileList[idx]=ff
|
||||||
|
self.duplicateNumber+=1
|
||||||
|
self.log.info("Ho rimosso {} duplicati di {} articoli..\n". format(self.duplicateNumber, len(duplicateList)))
|
||||||
|
pass
|
||||||
|
|
||||||
|
def saveSeparate(self):
|
||||||
|
self.log.info("Salvo gli articoli in file separati...")
|
||||||
|
self.log.debug("Persorso: {0}".format(self.paths['OUTworkPath'].format('nomeFile')))
|
||||||
|
for ff in self.fileList:
|
||||||
|
try:
|
||||||
|
if ff['duplicate'] == False:
|
||||||
|
fName=self.paths['OUTnameFormat'].format(title=slugify(ff['title'][:self.settings['maxTitleLen']]),\
|
||||||
|
filename=slugify(self.fileName),\
|
||||||
|
docnum=self.bodyCounter,\
|
||||||
|
papername=ff['newsPaperName'].strip(),\
|
||||||
|
**ff['date'])
|
||||||
|
out=open(self.paths['OUTworkPath']+'{0}'.format(fName),'wb')
|
||||||
|
if self.settings['includeTitle']:
|
||||||
|
ff['content'] = ff['title']+os.linesep+ff['content']
|
||||||
|
out.write(ff['content'].encode(self.settings['encoding']))
|
||||||
|
out.close()
|
||||||
|
self.bodyCounter+=1
|
||||||
|
except IOError as e:
|
||||||
|
self.log.error("Qualcosa e\' andato storto, non riesco a scrivere il file: {}".format(e))
|
||||||
|
continue
|
||||||
|
pass
|
||||||
|
|
||||||
|
def saveBody(self):
|
||||||
|
print('Salvo gli articoli in un singolo file vicino agli originali...')
|
||||||
|
print ('Persorso: {0}'.format(self.paths['OUTworkPath'].format('nomeFile')))
|
||||||
|
try:
|
||||||
|
fName=slugify(self.fileName)
|
||||||
|
fName='BODYFILE_{0}_{1}.txt'.format(self.fileCounter,fName[:self.settings['maxTitleLen']])
|
||||||
|
fileContent = os.linesep.join([cc['content'] for cc in self.fileList])
|
||||||
|
out=open(self.paths['OUTworkPath']+'{0}'.format(fName),'wb')
|
||||||
|
out.write(fileContent.encode(self.settings['encoding']))
|
||||||
|
out.close()
|
||||||
|
except IOError as e:
|
||||||
|
print("OOPS! Qualcosa e\' andato storto, non riesco a scrivere il file: {}".format(e))
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
logg = fancyLogger(name="LibSplit")
|
||||||
|
spp = bananaSPLITTER(fileParams="testfile.txt", logger=logg)
|
||||||
|
|
||||||
|
|
||||||
82
bananaSPLIT/libbananasplit/testEN.json
Normal file
82
bananaSPLIT/libbananasplit/testEN.json
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
{
|
||||||
|
"version": "v1.1a",
|
||||||
|
"logger": {
|
||||||
|
"logFile": "D:\\Test\\bananaSPLIT.log",
|
||||||
|
"logFormat": "%(asctime)s|%(levelname)-8s| %(message)-50s",
|
||||||
|
"logTimeFormat": "%m-%d %H:%M:%S"
|
||||||
|
},
|
||||||
|
"splitter": {
|
||||||
|
"paths": {
|
||||||
|
"INworkPath": "D:\\Test\\",
|
||||||
|
"OUTworkPath": "D:\\Test\\Separati\\",
|
||||||
|
"OUTnameFormat": "TEST_{docnum}_{year:04d}{month:02d}{day:02d}_{title}.txt"
|
||||||
|
},
|
||||||
|
"docStruct": {
|
||||||
|
"docSep": "\\s*Copyright [(0-9)]+",
|
||||||
|
"dateFormat": "{month} {day:d}, {year:d}{}",
|
||||||
|
"dateWords": [
|
||||||
|
"January",
|
||||||
|
"February",
|
||||||
|
"March",
|
||||||
|
"April",
|
||||||
|
"May",
|
||||||
|
"June",
|
||||||
|
"July",
|
||||||
|
"August",
|
||||||
|
"September",
|
||||||
|
"October",
|
||||||
|
"November",
|
||||||
|
"December"
|
||||||
|
],
|
||||||
|
"headWords": [
|
||||||
|
"BYLINE:",
|
||||||
|
"SECTION:",
|
||||||
|
"LENGTH:",
|
||||||
|
"DATELINE:",
|
||||||
|
"HIGHLIGHT:",
|
||||||
|
"Email:"
|
||||||
|
],
|
||||||
|
"tailWords": [
|
||||||
|
"Newstex ID:",
|
||||||
|
"NOTES:",
|
||||||
|
"LANGUAGE:",
|
||||||
|
"GRAPHIC:",
|
||||||
|
"TYPE:",
|
||||||
|
"URL:",
|
||||||
|
"LOAD-DATE:",
|
||||||
|
"PUBLICATION-TYPE:",
|
||||||
|
"DOCUMENT-TYPE:",
|
||||||
|
"CHARTS:",
|
||||||
|
"JOURNAL-CODE:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"encoding": "utf-8",
|
||||||
|
"monthPosition": 0,
|
||||||
|
"getNewsPaperName": true,
|
||||||
|
"nameNotFoundStr": "ND",
|
||||||
|
"includeTitle": true,
|
||||||
|
"removeDuplicates": true,
|
||||||
|
"showSkipped": false,
|
||||||
|
"showRemovedDuplicates": true,
|
||||||
|
"maxTitleLen": 32,
|
||||||
|
"loadTXT": true,
|
||||||
|
"loadDOCX": false,
|
||||||
|
"removeOldFiles": true,
|
||||||
|
"saveSeparateFiles": true,
|
||||||
|
"saveBodyFile": true,
|
||||||
|
"saveBodyNumber": true,
|
||||||
|
"delLF": false,
|
||||||
|
"delWordBreak": true,
|
||||||
|
"delChars": [
|
||||||
|
"'",
|
||||||
|
"@",
|
||||||
|
"#",
|
||||||
|
"$",
|
||||||
|
"%",
|
||||||
|
"^",
|
||||||
|
"&"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
79
bananaSPLIT/libbananasplit/testITA.json
Normal file
79
bananaSPLIT/libbananasplit/testITA.json
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
{
|
||||||
|
"version": "v1.1a",
|
||||||
|
"logger": {
|
||||||
|
"logFile": "D:\\Test\\bananaSPLIT.log",
|
||||||
|
"logFormat": "%(asctime)s|%(levelname)-8s| %(message)-50s",
|
||||||
|
"logTimeFormat": "%m-%d %H:%M:%S"
|
||||||
|
},
|
||||||
|
"splitter": {
|
||||||
|
"paths": {
|
||||||
|
"INworkPath": "D:\\Test\\",
|
||||||
|
"OUTworkPath": "D:\\Test\\Separati\\",
|
||||||
|
"OUTnameFormat": "TEST_{docnum}_{year:04d}{month:02d}{day:02d}_{title}.txt"
|
||||||
|
},
|
||||||
|
"docStruct": {
|
||||||
|
"docSep": "Copyright [(0-9)]+",
|
||||||
|
"dateFormat": "{day:d} {month} {year:d} {}",
|
||||||
|
"dateWords": [
|
||||||
|
"Gennaio",
|
||||||
|
"Febbraio",
|
||||||
|
"Marzo",
|
||||||
|
"Aprile",
|
||||||
|
"Maggio",
|
||||||
|
"Giugno",
|
||||||
|
"Luglio",
|
||||||
|
"Agosto",
|
||||||
|
"Settembre",
|
||||||
|
"Ottobre",
|
||||||
|
"Novembre",
|
||||||
|
"Dicembre"
|
||||||
|
],
|
||||||
|
"headWords": [
|
||||||
|
"BYLINE:",
|
||||||
|
"SECTION:",
|
||||||
|
"LENGTH:",
|
||||||
|
"DATELINE:",
|
||||||
|
"HIGHLIGHT:",
|
||||||
|
"Email:"
|
||||||
|
],
|
||||||
|
"tailWords": [
|
||||||
|
"LANGUAGE:",
|
||||||
|
"GRAPHIC:",
|
||||||
|
"TYPE:",
|
||||||
|
"URL:",
|
||||||
|
"LOAD-DATE:",
|
||||||
|
"PUBLICATION-TYPE:",
|
||||||
|
"DOCUMENT-TYPE:",
|
||||||
|
"CHARTS:"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"encoding": "utf-8",
|
||||||
|
"monthPosition": 0,
|
||||||
|
"getNewsPaperName": true,
|
||||||
|
"nameNotFoundStr": "ND",
|
||||||
|
"includeTitle": true,
|
||||||
|
"removeDuplicates": true,
|
||||||
|
"showSkipped": false,
|
||||||
|
"showRemovedDuplicates": true,
|
||||||
|
"maxTitleLen": 32,
|
||||||
|
"loadTXT": true,
|
||||||
|
"loadDOCX": false,
|
||||||
|
"removeOldFiles": true,
|
||||||
|
"saveSeparateFiles": true,
|
||||||
|
"saveBodyFile": true,
|
||||||
|
"saveBodyNumber": true,
|
||||||
|
"delLF": false,
|
||||||
|
"delWordBreak": true,
|
||||||
|
"delChars": [
|
||||||
|
"'",
|
||||||
|
"@",
|
||||||
|
"#",
|
||||||
|
"$",
|
||||||
|
"%",
|
||||||
|
"^",
|
||||||
|
"&"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
bananaSPLIT/libtestmain.py
Normal file
19
bananaSPLIT/libtestmain.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
'''
|
||||||
|
Created on 1 dic 2019
|
||||||
|
|
||||||
|
@author: Emanuele Trabattoni
|
||||||
|
'''
|
||||||
|
import os
|
||||||
|
from libsplit import bananaSPLITTER
|
||||||
|
from libconfload import bananaCONF
|
||||||
|
from libfancylogger import fancyLogger
|
||||||
|
|
||||||
|
print(os.getcwd())
|
||||||
|
logger = fancyLogger(fileLog = False)
|
||||||
|
confl = bananaCONF(workdir=r"./libbananasplit", logger=logger)
|
||||||
|
splconf = confl.use("testEN")
|
||||||
|
splitter = bananaSPLITTER()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user