Compare commits
10 Commits
dc58a0efbb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fd290273ee | |||
| e177c4c2c4 | |||
| 040afc6757 | |||
| 394241706d | |||
| fef88af78d | |||
| ff7d878361 | |||
| 88d6d553e7 | |||
| 64cc1063bd | |||
| 00c85679a2 | |||
| 8a2d4d3ee6 |
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
// Usare IntelliSense per informazioni sui possibili attributi.
|
||||||
|
// Al passaggio del mouse vengono visualizzate le descrizioni degli attributi esistenti.
|
||||||
|
// Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Python: File corrente",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${file}",
|
||||||
|
"console": "integratedTerminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import ssl
|
# import ssl
|
||||||
import pika
|
import pika
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
@@ -11,6 +11,7 @@ import sqlite3
|
|||||||
|
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from smtplib import SMTP_SSL as SMTP, SMTPException, SMTPAuthenticationError
|
from smtplib import SMTP_SSL as SMTP, SMTPException, SMTPAuthenticationError
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
@@ -42,13 +43,11 @@ def send_mail(sev, msg, cfg):
|
|||||||
conn.sendmail(cfg.sender, cfg.receivers, msg.as_string())
|
conn.sendmail(cfg.sender, cfg.receivers, msg.as_string())
|
||||||
except SMTPAuthenticationError:
|
except SMTPAuthenticationError:
|
||||||
logging.error(
|
logging.error(
|
||||||
"PID {:>5} >> Mail failed: {}.".format(
|
"Mail failed: {}.".format("SMTP authentication error")
|
||||||
os.getpid(), "SMTP authentication error"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
logging.info(
|
logging.info(
|
||||||
"PID {:>5} >> Mail failed: {}.".format(os.getpid(), "CUSTOM_ERROR")
|
"Mail failed: {}.".format("CUSTOM_ERROR")
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
conn.quit()
|
conn.quit()
|
||||||
@@ -73,23 +72,21 @@ class mq:
|
|||||||
|
|
||||||
def write(self, msg, cfg):
|
def write(self, msg, cfg):
|
||||||
try:
|
try:
|
||||||
|
props = pika.BasicProperties(
|
||||||
|
delivery_mode=2,
|
||||||
|
content_encoding='utf-8',
|
||||||
|
timestamp=msg["timestamp"],)
|
||||||
self.channel.basic_publish(
|
self.channel.basic_publish(
|
||||||
exchange="",
|
exchange="",
|
||||||
routing_key=cfg.csv_queue,
|
routing_key=cfg.csv_queue,
|
||||||
body=msg,
|
body=msg["payload"],
|
||||||
properties=pika.BasicProperties(
|
properties=props
|
||||||
delivery_mode=2, # make message persistent
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
logging.info(
|
logging.info(
|
||||||
"PID {:>5} >> write message {} in queue".format(
|
"Write message {} in queue".format(msg))
|
||||||
os.getpid(), msg)
|
|
||||||
)
|
|
||||||
except:
|
except:
|
||||||
logging.error(
|
logging.error(
|
||||||
"PID {:>5} >> error write message {} in queue".format(
|
"Error write message {} in queue".format(msg))
|
||||||
os.getpid(), msg)
|
|
||||||
)
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.channel.close()
|
self.channel.close()
|
||||||
@@ -150,16 +147,14 @@ class ASEHandler(FTPHandler):
|
|||||||
if not os.stat(file).st_size:
|
if not os.stat(file).st_size:
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
logging.info(
|
logging.info(
|
||||||
"PID {:>5} >> file {} was empty: removed.".format(
|
"File {} was empty: removed.".format(file))
|
||||||
os.getpid(), file)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
cfg = self.cfg
|
cfg = self.cfg
|
||||||
path, filenameExt = os.path.split(file)
|
path, filenameExt = os.path.split(file)
|
||||||
filename, fileExtension = os.path.splitext(filenameExt)
|
filename, fileExtension = os.path.splitext(filenameExt)
|
||||||
|
if (fileExtension.upper() in (cfg.fileext)):
|
||||||
if m := re.match(
|
if m := re.match(
|
||||||
r"^(G\d\d\d)_(ID\d\d\d\d)_(DT\d\d\d\d)_(\d\d)(\d\d)(\d\d\d\d)(\d\d)(\d\d)(\d\d)$",
|
r"^(G\d\d\d|GFLOW)_(ID\d\d\d\d)_(DT\d\d\d\d)_(\d\d)(\d\d)(\d\d\d\d|\d\d)(\d\d)(\d\d)(\d\d)$",
|
||||||
filename,
|
filename,
|
||||||
re.I,
|
re.I,
|
||||||
):
|
):
|
||||||
@@ -169,6 +164,7 @@ class ASEHandler(FTPHandler):
|
|||||||
toolType = "N/A"
|
toolType = "N/A"
|
||||||
fileDate = m.group(6) + "/" + m.group(5) + "/" + m.group(4)
|
fileDate = m.group(6) + "/" + m.group(5) + "/" + m.group(4)
|
||||||
fileTime = m.group(7) + ":" + m.group(8) + ":" + m.group(9)
|
fileTime = m.group(7) + ":" + m.group(8) + ":" + m.group(9)
|
||||||
|
|
||||||
elif re.match(
|
elif re.match(
|
||||||
r"^(\d\d_\d\d\d\d|)(DT\d\d\d\d|LOC\d\d\d\d|GD\d\d\d\d)$", filename, re.I
|
r"^(\d\d_\d\d\d\d|)(DT\d\d\d\d|LOC\d\d\d\d|GD\d\d\d\d)$", filename, re.I
|
||||||
):
|
):
|
||||||
@@ -201,21 +197,18 @@ class ASEHandler(FTPHandler):
|
|||||||
toolName = m3.group(2).upper()
|
toolName = m3.group(2).upper()
|
||||||
else:
|
else:
|
||||||
toolType = "".join(
|
toolType = "".join(
|
||||||
re.findall("^[a-zA-Z]+", m3.group(1))
|
re.findall(
|
||||||
|
"^[a-zA-Z]+", m3.group(1))
|
||||||
).upper()
|
).upper()
|
||||||
toolName = m3.group(1).upper()
|
toolName = m3.group(1).upper()
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
logging.error(
|
logging.error(
|
||||||
"PID {:>5} >> Error: {}.".format(
|
"Error: {}.".format(sys.exc_info()[1]))
|
||||||
os.getpid(), sys.exc_info()[1]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
fileCsv.close
|
fileCsv.close
|
||||||
|
|
||||||
logging.info(
|
logging.info(
|
||||||
"PID {:>5} >> {} - {} - {} - {} - {} {}.".format(
|
"{} - {} - {} - {} - {} {}.".format(
|
||||||
os.getpid(),
|
|
||||||
unitType,
|
unitType,
|
||||||
unitName,
|
unitName,
|
||||||
toolName,
|
toolName,
|
||||||
@@ -224,7 +217,8 @@ class ASEHandler(FTPHandler):
|
|||||||
fileTime,
|
fileTime,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
newPath = cfg.csvfs + self.username + "/received/" + unitName.upper() + "/"
|
newPath = cfg.csvfs + "/" + self.username + "/received/" + \
|
||||||
|
unitName.upper() + "/"
|
||||||
newFilename = (
|
newFilename = (
|
||||||
newPath + filename + "_" +
|
newPath + filename + "_" +
|
||||||
str(ts.timestamp("tms") + fileExtension)
|
str(ts.timestamp("tms") + fileExtension)
|
||||||
@@ -233,54 +227,38 @@ class ASEHandler(FTPHandler):
|
|||||||
os.rename(file, fileRenamed)
|
os.rename(file, fileRenamed)
|
||||||
try:
|
try:
|
||||||
os.makedirs(newPath)
|
os.makedirs(newPath)
|
||||||
logging.info(
|
logging.info("Path {} created.".format(newPath))
|
||||||
"PID {:>5} >> path {} created.".format(
|
|
||||||
os.getpid(), newPath)
|
|
||||||
)
|
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
logging.info(
|
logging.info("Path {} already exists.".format(newPath))
|
||||||
"PID {:>5} >> path {} already exists.".format(
|
|
||||||
os.getpid(), newPath)
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
shutil.move(fileRenamed, newFilename)
|
shutil.move(fileRenamed, newFilename)
|
||||||
logging.info(
|
logging.info("{} moved into {}.".format(
|
||||||
"PID {:>5} >> {} moved into {}.".format(
|
filenameExt, newFilename))
|
||||||
os.getpid(), filenameExt, newFilename
|
|
||||||
)
|
|
||||||
)
|
|
||||||
except OSError:
|
except OSError:
|
||||||
logging.error(
|
logging.error("Error to move {} into {}.".format(
|
||||||
"PID {:>5} >> Error to move {} into {}.".format(
|
filenameExt, newFilename))
|
||||||
os.getpid(), filenameExt, newFilename
|
|
||||||
)
|
|
||||||
)
|
|
||||||
send_mail(
|
send_mail(
|
||||||
"Error", "OS error move " + filenameExt + " to " + newFilename, cfg
|
"Error", "OS error move " + filenameExt + " to " + newFilename, cfg
|
||||||
)
|
)
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
mq_message = "{};{};{};{};{};{};{}".format(
|
mq_message = {"payload": "{};{};{};{};{};{};{}".format(
|
||||||
unitType,
|
unitType,
|
||||||
unitName,
|
unitName,
|
||||||
toolName,
|
toolName,
|
||||||
toolType,
|
toolType,
|
||||||
df.dateFmt(fileDate),
|
df.dateFmt(fileDate),
|
||||||
fileTime,
|
fileTime,
|
||||||
newFilename,
|
newFilename),
|
||||||
)
|
"timestamp": int(datetime.timestamp(now)*1000000)
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
queue = mq(cfg)
|
queue = mq(cfg)
|
||||||
queue.write(mq_message, cfg)
|
queue.write(mq_message, cfg)
|
||||||
logging.info(
|
logging.info("Queue message: {}.".format(mq_message))
|
||||||
"PID {:>5} >> queue message: {}.".format(
|
|
||||||
os.getpid(), mq_message)
|
|
||||||
)
|
|
||||||
except:
|
except:
|
||||||
logging.error(
|
logging.error(
|
||||||
"PID {:>5} >> Error to put message in queue: {}.".format(
|
"Error to put message in queue: {}.".format(mq_message))
|
||||||
os.getpid(), mq_message
|
|
||||||
)
|
|
||||||
)
|
|
||||||
send_mail(
|
send_mail(
|
||||||
"Error", "Error to put message " + mq_message + " in queue.", cfg
|
"Error", "Error to put message " + mq_message + " in queue.", cfg
|
||||||
)
|
)
|
||||||
@@ -316,11 +294,7 @@ class ASEHandler(FTPHandler):
|
|||||||
(user, hash, cfg.virtpath + user, 'elmw'))
|
(user, hash, cfg.virtpath + user, 'elmw'))
|
||||||
con.commit()
|
con.commit()
|
||||||
con.close()
|
con.close()
|
||||||
logging.info(
|
logging.info("User {} created.".format(user))
|
||||||
"PID {:>5} >> User {} created.".format(
|
|
||||||
os.getpid(), user
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.respond('200 SITE ADDU successful.')
|
self.respond('200 SITE ADDU successful.')
|
||||||
except:
|
except:
|
||||||
self.respond('501 SITE ADDU failed.')
|
self.respond('501 SITE ADDU failed.')
|
||||||
@@ -339,11 +313,8 @@ class ASEHandler(FTPHandler):
|
|||||||
cur.execute("DELETE FROM virtusers WHERE user = ?", (user,))
|
cur.execute("DELETE FROM virtusers WHERE user = ?", (user,))
|
||||||
con.commit()
|
con.commit()
|
||||||
con.close()
|
con.close()
|
||||||
logging.info(
|
logging.info("User {} deleted.".format(user))
|
||||||
"PID {:>5} >> User {} deleted.".format(
|
# self.push(' The user path has not been removed!\r\n')
|
||||||
os.getpid(), user
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.respond('200 SITE DELU successful.')
|
self.respond('200 SITE DELU successful.')
|
||||||
|
|
||||||
except:
|
except:
|
||||||
@@ -361,7 +332,7 @@ class ASEHandler(FTPHandler):
|
|||||||
self.push("214-The following virtual users are defined:\r\n")
|
self.push("214-The following virtual users are defined:\r\n")
|
||||||
for row in cur.execute("SELECT * FROM virtusers").fetchall():
|
for row in cur.execute("SELECT * FROM virtusers").fetchall():
|
||||||
users_list.append(
|
users_list.append(
|
||||||
" Username: " + row[0] + " - Perms: " + row[3] + "\r\n")
|
" Username: " + row[0] + "\tPerms: " + row[3] + "\r\n")
|
||||||
con.close()
|
con.close()
|
||||||
self.push(''.join(users_list))
|
self.push(''.join(users_list))
|
||||||
self.respond("214 LSTU SITE command successful.")
|
self.respond("214 LSTU SITE command successful.")
|
||||||
@@ -393,8 +364,7 @@ def main():
|
|||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logging.info(
|
logging.info(
|
||||||
"PID {:>5} >> Info: {}.".format(
|
"Info: {}.".format("Shutdown requested...exiting")
|
||||||
os.getpid(), "Shutdown requested...exiting")
|
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
print(
|
print(
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ Parts you might want to customize are:
|
|||||||
Authors:
|
Authors:
|
||||||
- Ben Timby - btimby <at> gmail.com
|
- Ben Timby - btimby <at> gmail.com
|
||||||
- Giampaolo Rodola' - g.rodola <at> gmail.com
|
- Giampaolo Rodola' - g.rodola <at> gmail.com
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
|
# to generete adminuser password hash:
|
||||||
|
# python3 -c 'from hashlib import md5;print(md5("????admin-password???".encode("UTF-8")).hexdigest())'
|
||||||
[ftpserver]
|
[ftpserver]
|
||||||
firstPort = 40000
|
firstPort = 40000
|
||||||
logFilename = ./ftppylog.log
|
logFilename = ./ftppylog.log
|
||||||
proxyAddr = 0.0.0.0
|
proxyAddr = 0.0.0.0
|
||||||
portRangeWidth = 50
|
portRangeWidth = 500
|
||||||
virtusersdb = /home/alex/aseftp/virtusers.db
|
virtusersdb = /home/alex/aseftp/virtusers.db
|
||||||
virtpath = /home/alex/aseftp/
|
virtpath = /home/alex/aseftp/
|
||||||
adminuser = admin|c8cf955bd8b8a78419013b831e627eb2|/home/alex/aseftp/|elradfmwMT
|
adminuser = admin|c8cf955bd8b8a78419013b831e627eb2|/home/alex/aseftp/|elradfmwMT
|
||||||
servertype = FTPHandler
|
servertype = FTPHandler
|
||||||
certfile = /home/alex/aseftp/keycert.pem
|
certfile = /home/alex/aseftp/keycert.pem
|
||||||
|
fileext = .CSV|.txt
|
||||||
#servertype = FTPHandler/TLS_FTPHandler
|
#servertype = FTPHandler/TLS_FTPHandler
|
||||||
|
|
||||||
|
|
||||||
@@ -22,18 +25,18 @@
|
|||||||
bbbbb
|
bbbbb
|
||||||
ccccc
|
ccccc
|
||||||
subject = ciao a domani
|
subject = ciao a domani
|
||||||
debug = 1
|
debug = 0
|
||||||
|
|
||||||
[mqserver]
|
[mqserver]
|
||||||
hostname = 192.168.1.241
|
hostname = galera1
|
||||||
port = 5672
|
port = 5672
|
||||||
user = alex
|
user = asemq
|
||||||
password = batt1l0
|
password = Ase2021
|
||||||
csvQueue = task_queue
|
csvQueue = task_queue
|
||||||
elabQueue = elab_queue
|
elabQueue = elab_queue
|
||||||
|
|
||||||
[csvfs]
|
[csvfs]
|
||||||
path = /home/
|
path = /home/alex/aseftp/csvfs/
|
||||||
|
|
||||||
[csvelab]
|
[csvelab]
|
||||||
logFilename = csvElab.log
|
logFilename = csvElab.log
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ from configparser import ConfigParser
|
|||||||
class config:
|
class config:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
c = ConfigParser()
|
c = ConfigParser()
|
||||||
c.read(["/etc/aseftp/ftpcsvreceiver.ini", "./ftpcsvreceiver.ini"])
|
c.read(["/etc/aseftp/ftpcsvreceiver.ini", "./ftpcsvreceiver.ini",
|
||||||
|
"./ase-receiver/ase-receiver/ftpcsvreceiver.ini"])
|
||||||
# FTP setting
|
# FTP setting
|
||||||
self.firstport = c.getint("ftpserver", "firstPort")
|
self.firstport = c.getint("ftpserver", "firstPort")
|
||||||
self.logfilename = c.get("ftpserver", "logFilename")
|
self.logfilename = c.get("ftpserver", "logFilename")
|
||||||
@@ -18,6 +19,7 @@ class config:
|
|||||||
self.adminuser = c.get("ftpserver", "adminuser").split("|")
|
self.adminuser = c.get("ftpserver", "adminuser").split("|")
|
||||||
self.servertype = c.get("ftpserver", "servertype")
|
self.servertype = c.get("ftpserver", "servertype")
|
||||||
self.certfile = c.get("ftpserver", "certfile")
|
self.certfile = c.get("ftpserver", "certfile")
|
||||||
|
self.fileext = c.get("ftpserver", "fileext").upper().split("|")
|
||||||
|
|
||||||
# MAIL setting
|
# MAIL setting
|
||||||
self.smtphost = c.get("mailserver", "hostname")
|
self.smtphost = c.get("mailserver", "hostname")
|
||||||
|
|||||||
@@ -2,24 +2,27 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
from datetime import datetime
|
||||||
|
from re import search
|
||||||
|
|
||||||
|
|
||||||
def dateFmt(date):
|
def dateFmt(date):
|
||||||
t = date.replace("/", "-")
|
t = date.replace("/", "-")
|
||||||
try:
|
if search('^\d\d\d\d-\d\d-\d\d$', t):
|
||||||
datetime.datetime.strptime(t, "%Y-%m-%d")
|
d = datetime.strptime(t, "%Y-%m-%d")
|
||||||
return t
|
elif search('^\d\d-\d\d-\d\d$', t):
|
||||||
except ValueError:
|
d = datetime.strptime(t, "%y-%m-%d")
|
||||||
d = datetime.datetime.strptime(t, "%d-%m-%Y")
|
elif search('^\d\d-\d\d-\d\d\d\d$', t):
|
||||||
return datetime.datetime.strftime(d, "%Y-%m-%d")
|
d = datetime.strptime(t, "%d-%m-%Y")
|
||||||
|
return datetime.strftime(d, "%Y-%m-%d")
|
||||||
|
|
||||||
|
|
||||||
def dateTimeFmt(date):
|
def dateTimeFmt(date):
|
||||||
t = date.replace("/", "-")
|
t = date.replace("/", "-")
|
||||||
try:
|
if search('^\d\d\d\d-\d\d-\d\d$', t):
|
||||||
datetime.datetime.strptime(t, "%Y-%m-%d %H:%M:%S")
|
d = datetime.strptime(t, "%Y-%m-%d %H:%M:%S")
|
||||||
return t
|
elif search('^\d\d-\d\d-\d\d$', t):
|
||||||
except ValueError:
|
d = datetime.strptime(t, "%y-%m-%d %H:%M:%S")
|
||||||
d = datetime.datetime.strptime(t, "%d-%m-%Y %H:%M:%S")
|
elif search('^\d\d-\d\d-\d\d\d\d$', t):
|
||||||
return datetime.datetime.strftime(d, "%Y-%m-%d %H:%M:%S")
|
d = datetime.strptime(t, "%d-%m-%Y %H:%M:%S")
|
||||||
|
return datetime.strftime(d, "%Y-%m-%d")
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def timestamp(t):
|
def timestamp(t):
|
||||||
fmt = {"log": "%Y-%m-%d %H:%M:%S", "tms": "%Y%m%d%H%M%S"}
|
fmt = {"log": "%Y-%m-%d %H:%M:%S", "tms": "%Y%m%d%H%M%S"}
|
||||||
return datetime.datetime.now().strftime(fmt[t])
|
return datetime.now().strftime(fmt[t])
|
||||||
|
|||||||
12
pivot_pianificazione.py
Executable file
12
pivot_pianificazione.py
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
dm = {"gennaio ": "01/", "febbraio" }
|
||||||
|
di = {1: "A", 2: "B"}
|
||||||
|
|
||||||
|
pianificazioni = pd.read_csv("/home/alex/Documenti/Cdig_Dettaglio_Pianificazione_Piatta.csv")
|
||||||
|
|
||||||
|
pianificazioni.pivot_table(index=['Attività','Tipo_Progetto','Descrizione_Progetto'],columns='Mese',values='perc_pianificazione',aggfunc = "sum", margins = True, fill_value = "")
|
||||||
|
print(pianificazioni.pivot_table(index='Attività', values='GG pianificati'))
|
||||||
Reference in New Issue
Block a user