-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge_creds.groovy
65 lines (53 loc) · 1.79 KB
/
merge_creds.groovy
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
/* :name = Merge Creds Files :description=
*
* @author Manuel Souto Pico
* @date 2024-06-05
* @version 0.0.2
*/
import org.omegat.util.StaticUtils
import groovy.io.FileType
import java.text.SimpleDateFormat
import java.util.Date
import java.util.TimeZone
// define constants
configDir = StaticUtils.getConfigDir()
credsDir = new File(configDir + File.separator + "creds")
if (!credsDir.exists()) { credsDir.mkdirs() }
credsFile = new File(configDir + File.separator + "repositories.properties")
// create timestamps
def date = new Date()
def bakFormat = new SimpleDateFormat("yyyyMMdd.HHmmss")
def bakFormattedDate = bakFormat.format(date)
def headerFormat = new SimpleDateFormat("'#'EEE MMM dd HH:mm:ss z yyyy")
headerFormat.setTimeZone(TimeZone.getTimeZone("CET"))
def formattedDate = headerFormat.format(date)
// create or backup creds file
if (credsFile.exists()) {
// make backup
def backupFilePath = credsFile.getAbsolutePath() + '.' + bakFormattedDate + '.bak'
def backupFile = new File(backupFilePath)
backupFile.text = credsFile.text
} else {
console.println("Create the file if it doesn't exist.")
credsFile.createNewFile() // empty
// credsFile.text = 'formattedDate'
// credsFile.write(formattedDate)
}
// collect creds project files
def credProjFiles = []
credsDir.eachFile (FileType.FILES) { file ->
// check that proj suffix belongs to a validated list? ["pisa", "ysc", "etc"]
if (!file.getAbsolutePath().endsWith(".done")) {
credProjFiles << file
}
}
credProjFiles.each{ file ->
// merge all proj creds
credsFile.append(file.getText())
// disable the process proj creds files
def doneFilePath = file.getAbsolutePath() + '.done'
def doneFile = new File(doneFilePath)
file.renameTo(doneFile)
}
// todo: dedupe lines? (duplicate lines seem harmless, though)
return