Révision 3236
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/InstallAndUpdateMacroMacro.groovy (revision 3236) | ||
---|---|---|
1 |
import org.txm.Toolbox |
|
2 |
import org.txm.utils.ConsoleProgressBar |
|
3 |
import org.txm.utils.io.IOUtils |
|
4 |
|
|
5 |
def groovyUserDirectory = new File(Toolbox.getTxmHomePath() + "/scripts/groovy/user/org/txm/macro/"); |
|
6 |
|
|
7 |
if (!groovyUserDirectory.exists()) { |
|
8 |
groovyUserDirectory.mkdirs(); |
|
9 |
} |
|
10 |
|
|
11 |
if (!groovyUserDirectory.exists()) { |
|
12 |
monitorShowError("Le répertoire $groovyUserDirectory n'a pas pu être créé. Abandon.") |
|
13 |
return; |
|
14 |
} |
|
15 |
@Field @Option(name="macroPaths", usage="Comma separated list of macro paths", widget="String", required=true, def="") |
|
16 |
def macroPaths |
|
17 |
|
|
18 |
@Field @Option(name="svnRepository", usage="http based URL of TXM's SVN ", widget="String", required=true, def="http://forge.cbp.ens-lyon.fr/svn/txm/tmp/org.txm.groovy.core/src/groovy/org/txm/macro/") |
|
19 |
def svnRepository |
|
20 |
|
|
21 |
@Field @Option(name="debug", usage="Show devug messages", widget="Boolean", required=false, def="false") |
|
22 |
def debug |
|
23 |
|
|
24 |
if (!ParametersDialog.open(this)) return false; |
|
25 |
|
|
26 |
if (!svnRepository.endsWith("/")) svnRepository += "/" |
|
27 |
|
|
28 |
def macros = macroPaths.split(",").collect(){it.trim()} |
|
29 |
def copy = [] |
|
30 |
copy.addAll(macros) |
|
31 |
macros.clear() |
|
32 |
for (def m : copy) { |
|
33 |
macros.addAll(getFiles(svnRepository, m, debug)) |
|
34 |
} |
|
35 |
|
|
36 |
|
|
37 |
print "Fetching ${macros.size()} files: " |
|
38 |
def errors = new LinkedHashMap() |
|
39 |
def updated = [] |
|
40 |
def news = [] |
|
41 |
for (def m : macros) { |
|
42 |
def f = new File(groovyUserDirectory, m) |
|
43 |
f.getParentFile().mkdirs() |
|
44 |
String remoteUrl = svnRepository+m |
|
45 |
try { |
|
46 |
|
|
47 |
if (debug) print "\n"+remoteUrl |
|
48 |
boolean replaced = f.exists() |
|
49 |
|
|
50 |
def file = new FileOutputStream(f) |
|
51 |
def out = new BufferedOutputStream(file) |
|
52 |
out << new URL(remoteUrl).openStream() |
|
53 |
out.close() |
|
54 |
|
|
55 |
if (replaced) { |
|
56 |
print "*" |
|
57 |
updated << m |
|
58 |
} else { |
|
59 |
print "." |
|
60 |
news << m |
|
61 |
} |
|
62 |
} catch(Exception e ) { |
|
63 |
print "x" |
|
64 |
errors[m] = e; |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
if (news.size() > 0 ) { |
|
69 |
println "\n${news.join(", ")} created." |
|
70 |
} |
|
71 |
|
|
72 |
if (updated.size() > 0 ) { |
|
73 |
println "\n${updated.join(", ")} updated." |
|
74 |
} |
|
75 |
|
|
76 |
if (errors.size() > 0) { |
|
77 |
println "\n${errors.keySet().join(", ")} failed:" |
|
78 |
println errors.values().join("\n\t") |
|
79 |
} |
|
80 |
|
|
81 |
def getFiles(def svnRepository, def m, def debug) { |
|
82 |
println "get files of $m" |
|
83 |
def files = [] |
|
84 |
try { |
|
85 |
|
|
86 |
//if (debug) println content |
|
87 |
if (m.endsWith("/")) { // || content.startsWith("<html><head><title>txm") // nag alternative |
|
88 |
if (!m.endsWith("/")) m += "/" |
|
89 |
|
|
90 |
def content = new URL(svnRepository+m).getText() |
|
91 |
|
|
92 |
content.findAll(/<li><a href="([^"]+)">([^<]+)<\/a><\/li>/) { li -> |
|
93 |
|
|
94 |
def name = li[2] |
|
95 |
if (name != "..") { |
|
96 |
files.addAll(getFiles(svnRepository, m +name, debug)) |
|
97 |
if (debug) println "add the '$name' file from '$m' content" |
|
98 |
} |
|
99 |
} |
|
100 |
} else { |
|
101 |
files << m |
|
102 |
} |
|
103 |
|
|
104 |
} catch(Exception e) { } |
|
105 |
|
|
106 |
return files |
|
107 |
} |
|
108 |
|
|
109 |
def monitorShowError(String message) { |
|
110 |
monitor.syncExec(new Runnable() { |
|
111 |
public void run() { |
|
112 |
org.eclipse.jface.dialogs.MessageDialog.openError(org.eclipse.swt.widgets.Display.getCurrent().getActiveShell(), "Error", message) |
|
113 |
} |
|
114 |
}); |
|
115 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/InstallAndUpdateMacrosMacro.groovy (revision 3236) | ||
---|---|---|
1 |
import org.txm.Toolbox |
|
2 |
import org.txm.utils.ConsoleProgressBar |
|
3 |
import org.txm.utils.io.IOUtils |
|
4 |
|
|
5 |
def groovyUserDirectory = new File(Toolbox.getTxmHomePath() + "/scripts/groovy/user/org/txm/macro/"); |
|
6 |
|
|
7 |
if (!groovyUserDirectory.exists()) { |
|
8 |
groovyUserDirectory.mkdirs(); |
|
9 |
} |
|
10 |
|
|
11 |
if (!groovyUserDirectory.exists()) { |
|
12 |
monitorShowError("Le répertoire $groovyUserDirectory n'a pas pu être créé. Abandon.") |
|
13 |
return; |
|
14 |
} |
|
15 |
@Field @Option(name="macroPaths", usage="Comma separated list of macro paths", widget="String", required=true, def="") |
|
16 |
def macroPaths |
|
17 |
|
|
18 |
@Field @Option(name="svnRepository", usage="http based URL of TXM's SVN ", widget="String", required=true, def="http://forge.cbp.ens-lyon.fr/svn/txm/tmp/org.txm.groovy.core/src/groovy/org/txm/macro/") |
|
19 |
def svnRepository |
|
20 |
|
|
21 |
@Field @Option(name="debug", usage="Show devug messages", widget="Boolean", required=false, def="false") |
|
22 |
def debug |
|
23 |
|
|
24 |
if (!ParametersDialog.open(this)) return false; |
|
25 |
|
|
26 |
if (!svnRepository.endsWith("/")) svnRepository += "/" |
|
27 |
|
|
28 |
def macros = macroPaths.split(",").collect(){it.trim()} |
|
29 |
def copy = [] |
|
30 |
copy.addAll(macros) |
|
31 |
macros.clear() |
|
32 |
for (def m : copy) { |
|
33 |
macros.addAll(getFiles(svnRepository, m, debug)) |
|
34 |
} |
|
35 |
|
|
36 |
|
|
37 |
print "Fetching ${macros.size()} files: " |
|
38 |
def errors = new LinkedHashMap() |
|
39 |
def updated = [] |
|
40 |
def news = [] |
|
41 |
for (def m : macros) { |
|
42 |
def f = new File(groovyUserDirectory, m) |
|
43 |
f.getParentFile().mkdirs() |
|
44 |
String remoteUrl = svnRepository+m |
|
45 |
try { |
|
46 |
|
|
47 |
if (debug) print "\n"+remoteUrl |
|
48 |
boolean replaced = f.exists() |
|
49 |
|
|
50 |
def file = new FileOutputStream(f) |
|
51 |
def out = new BufferedOutputStream(file) |
|
52 |
out << new URL(remoteUrl).openStream() |
|
53 |
out.close() |
|
54 |
|
|
55 |
if (replaced) { |
|
56 |
print "*" |
|
57 |
updated << m |
|
58 |
} else { |
|
59 |
print "." |
|
60 |
news << m |
|
61 |
} |
|
62 |
} catch(Exception e ) { |
|
63 |
print "x" |
|
64 |
errors[m] = e; |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
if (news.size() > 0 ) { |
|
69 |
println "\n${news.join(", ")} created." |
|
70 |
} |
|
71 |
|
|
72 |
if (updated.size() > 0 ) { |
|
73 |
println "\n${updated.join(", ")} updated." |
|
74 |
} |
|
75 |
|
|
76 |
if (errors.size() > 0) { |
|
77 |
println "\n${errors.keySet().join(", ")} failed:" |
|
78 |
println errors.values().join("\n\t") |
|
79 |
} |
|
80 |
|
|
81 |
def getFiles(def svnRepository, def m, def debug) { |
|
82 |
println "get files of $m" |
|
83 |
def files = [] |
|
84 |
try { |
|
85 |
|
|
86 |
//if (debug) println content |
|
87 |
if (m.endsWith("/")) { // || content.startsWith("<html><head><title>txm") // nag alternative |
|
88 |
if (!m.endsWith("/")) m += "/" |
|
89 |
|
|
90 |
def content = new URL(svnRepository+m).getText() |
|
91 |
|
|
92 |
content.findAll(/<li><a href="([^"]+)">([^<]+)<\/a><\/li>/) { li -> |
|
93 |
|
|
94 |
def name = li[2] |
|
95 |
if (name != "..") { |
|
96 |
files.addAll(getFiles(svnRepository, m +name, debug)) |
|
97 |
if (debug) println "add the '$name' file from '$m' content" |
|
98 |
} |
|
99 |
} |
|
100 |
} else { |
|
101 |
files << m |
|
102 |
} |
|
103 |
|
|
104 |
} catch(Exception e) { } |
|
105 |
|
|
106 |
return files |
|
107 |
} |
|
108 |
|
|
109 |
def monitorShowError(String message) { |
|
110 |
monitor.syncExec(new Runnable() { |
|
111 |
public void run() { |
|
112 |
org.eclipse.jface.dialogs.MessageDialog.openError(org.eclipse.swt.widgets.Display.getCurrent().getActiveShell(), "Error", message) |
|
113 |
} |
|
114 |
}); |
|
115 |
} |
Formats disponibles : Unified diff