3 |
3 |
Configuration des #log. pour l'importation scribe
|
4 |
4 |
"""
|
5 |
5 |
from os import makedirs
|
|
6 |
from os.path import expanduser
|
6 |
7 |
from shutil import copy
|
7 |
8 |
from os.path import basename, isdir, join
|
8 |
9 |
from pyeole.lock import acquire, release, is_locked
|
9 |
10 |
from pyeole.log import make_logger
|
10 |
11 |
from scribe.eoletools import format_current_date
|
11 |
|
from scribe.importation.config import LOGFILE, RAPPORTFILE, DEST_DIR
|
|
12 |
from scribe.importation.config import LOGFILE, RAPPORTFILE, DEST_DIR, DEFAULT_USER
|
12 |
13 |
|
13 |
14 |
LINE = "#########################################"
|
14 |
15 |
LOGFMT = "%(asctime)s - %(levelname)s %(message)s"
|
... | ... | |
64 |
65 |
print(msg)
|
65 |
66 |
log.error(msg)
|
66 |
67 |
|
67 |
|
def end_importation(mode):
|
|
68 |
def end_importation(mode, user=DEFAULT_USER):
|
68 |
69 |
"""
|
69 |
70 |
fin de l'importation
|
70 |
71 |
mode : console ou ead
|
... | ... | |
72 |
73 |
log.info(LINE)
|
73 |
74 |
log.info(" Fin de l'importation en mode %s" % mode)
|
74 |
75 |
log.info(LINE)
|
75 |
|
copy_info(RAPPORTFILE)
|
|
76 |
copy_info(RAPPORTFILE, user)
|
76 |
77 |
|
77 |
78 |
def write_info(line, filename):
|
78 |
79 |
"""
|
... | ... | |
90 |
91 |
fic.write(header+'\n')
|
91 |
92 |
fic.close()
|
92 |
93 |
|
93 |
|
def copy_info(src):
|
|
94 |
def copy_info(src, user=DEFAULT_USER):
|
94 |
95 |
"""
|
95 |
96 |
sauvegarde un fichier de comptes dans le perso d'admin
|
96 |
97 |
"""
|
97 |
|
if not isdir(DEST_DIR):
|
98 |
|
makedirs(DEST_DIR)
|
|
98 |
home_dir = expanduser("~{}".format(user))
|
|
99 |
dest_dir = join(home_dir, 'perso', 'importation')
|
|
100 |
if not isdir(dest_dir):
|
|
101 |
makedirs(dest_dir)
|
99 |
102 |
date = format_current_date('%Y%m%d_%H%M%S')
|
100 |
103 |
base, extension = basename(src).split('.')
|
101 |
104 |
# on se base sur le fait que filename se termine en .xxx
|
... | ... | |
103 |
106 |
dst = join(DEST_DIR, dname)
|
104 |
107 |
try:
|
105 |
108 |
copy(src, dst)
|
|
109 |
if user != DEFAULT_USER:
|
|
110 |
copy_info(src)
|
106 |
111 |
if extension == 'csv':
|
107 |
112 |
infolog("fichier des comptes copié dans :")
|
108 |
113 |
else:
|