1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
| ################################################################
# PARAMETRE
################################################################
-- Fichier source contenant les visuels recherchés
property IN_DIR : "/Volumes/Stock/01_Recherche par liste/"
--
-- Libraires
--
set cc to load script alias ((path to library folder as string) & "Scripts:easyProd_common:Common Code.app")
global cc
set libIMG to cc's load("LIB.BaseImage")
global libIMG
--
-- Constantes
--
property DIR_VISU : "Visuels"
property LOG_FILE : "extractionVisuels.log"
property MAX_PAQUET_VISU : 400
--
-- Fonctions
--
---------------------------------------------------------------------------------------------------------
-- Temps d'exécution
global startTime
set startTime to current date
cc's clean_terminal()
on getExecTime()
return cc's getTimeSince(startTime as string)
end getExecTime
on showMsg(msg)
cc's show_me((cc's getTimeSince(startTime) & ".. " & msg) as string)
end showMsg
--
-- Main
--
my showMsg("Extraction des infos du fchier ouvert dans TextWrangler")
tell application "TextWrangler"
set {chemin, contenu} to {file, contents} of document 1
end tell
set chemin to "" & chemin
set outDirOSX to text 1 thru (cc's lastPositionInString(":", "" & chemin)) of chemin
set outDirX to "" & POSIX path of outDirOSX
set visuDirOSX to outDirOSX & DIR_VISU & ":"
set visuDirX to "" & POSIX path of visuDirOSX
my showMsg("Création du répertoire Visuels dans le répertoire de sortie")
tell application "System Events"
try
make new folder at folder outDirOSX with properties {name:DIR_VISU}
on error
delete folder (visuDirOSX)
make new folder at folder outDirOSX with properties {name:DIR_VISU}
end try
end tell
my showMsg("Récupération des visuels")
set listeVisuels to paragraphs of contenu
set listeVisuelsOK to {}
set listeVisuelsKO to {}
set listeVisuelsDoublons to {}
set listeErreurs to {}
set totalVisus to length of listeVisuels
set indexVisu to 1
repeat with img in listeVisuels # items 1 thru MAX_PAQUET_VISU of
set img to "" & img
try
set imgPath to do shell script "find " & quoted form of IN_DIR & " -name " & img & "*"
if length of paragraphs of imgPath > 1 then
set end of listeVisuelsDoublons to img
my showMsg("→ Visuel en double : " & img)
else
log "find " & quoted form of visuDirX & " -name " & img & "*"
log imgPath
try
do shell script "cp -p " & quoted form of imgPath & " " & quoted form of visuDirX
set end of listeVisuelsOK to img
#if indexVisu = 50 then
# set indexVisu to 0
# my showMsg("→ Visuel OK : " & img)
#end if
my showMsg("→ Visuel " & totalVisus - indexVisu & "/" & totalVisus & " OK : " & img)
on error errMsg
log errMsg
set end of listeVisuelsKO to img
my showMsg("→ Visuel déjà copié : " & img)
# my showMsg("→ Visuel déjà copié : " & img & " - reste " & totalVisus - indexVisu)
end try
end if
on error errMsg
set end of listeErreurs to img & return & "(" & errMsg & ")"
my showMsg("→ Rejet : " & img)
# my showMsg("→ Rejet : " & img & " - reste " & totalVisus - indexVisu)
end try
set indexVisu to indexVisu + 1
end repeat
my showMsg("Ecriture du fichier de logs")
set logFileFullPath to quoted form of (outDirX & LOG_FILE)
do shell script "laDate=$(date '+%Y.%m.%d %H:%M:%S'); echo " & return & ¬
" Extraction de visuels " & return & ¬
"${laDate}" & return & return & " > " & logFileFullPath
if length of listeVisuelsOK > 0 then ¬
do shell script "echo " & return & ¬
"----- Visuels extraits :" & return & return & ¬
cc's listToString(listeVisuelsOK, return) & return & " >> " & logFileFullPath
if length of listeVisuelsKO > 0 then ¬
do shell script "echo " & return & return & ¬
"----- Visuels déjà copiés :" & return & return & cc's listToString(listeVisuelsKO, return) & return & " >> " & logFileFullPath
if length of listeVisuelsDoublons > 0 then ¬
do shell script "echo " & return & return & ¬
"----- Visuels en double :" & return & return & cc's listToString(listeVisuelsDoublons, return) & return & " >> " & logFileFullPath
if length of listeErreurs > 0 then
log cc's listToString(listeErreurs, return)
do shell script "echo " & return & return & ¬
"----- Rejets :" & return & return & cc's listToString(listeErreurs, return) & return & " >> " & logFileFullPath
my showMsg("Des erreurs ont été détectées.")
tell me
activate
display dialog ¬
("Exécution terminée." & linefeed & linefeed & ¬
"Regarder les logs pour afficher les erreurs.") ¬
buttons {"OK"} default button "OK" with title "Exécution terminée"
end tell
return
end if
my showMsg("Exécution terminée : aucune erreur détectée")
tell application "Finder" to reveal folder visuDirOSX
tell me
activate
display dialog ("Exécution terminée sans erreur") ¬
buttons {"OK"} default button "OK" with title "Exécution terminée"
end tell |
Partager