This repository has been archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
add-incremental.js
74 lines (67 loc) · 2.98 KB
/
add-incremental.js
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
var models = require('./models/');
var fs = require('fs');
var utils = require('./utils.js');
var buildInfo = require('yargs')
.usage('Usage: $0 [options]\n Adds a new incremental build to the database.')
.alias('active', 'a').boolean('active').describe('active', 'Marks the incremental as active (available for download) or not.')
.alias('filename', 'f').nargs('filename', 1).describe('filename', 'The resulting filename.')
.alias('filesize', 'i').nargs('filesize', 1).number('filesize').describe('filesize', 'The size (in bytes) of the incremental update file.')
.alias('from_target_files', 'F').nargs('from_target_files', 1).describe('from_target_files', 'The name of the "target files ZIP" of the incremental\'s "source".')
.alias('md5sum', 'm').nargs('md5sum', 1).describe('md5sum', 'The build\'s md5sum.')
.alias('subdirectory', 's').nargs('subdirectory', 1).describe('subdirectory', 'The subdirectory from which the file can be downloaded.')
.alias('timestamp', 't').nargs('timestamp', 1).number('timestamp').describe('timestamp', 'The build\'s timestamp as "unixepoch" timestamp ("ro.build.date.utc").')
.alias('to_target_files', 'T').nargs('to_target_files', 1).describe('to_target_files', 'The name of the "target files ZIP" of the incremental\'s "target".')
.demandOption(['active', 'device', 'filename', 'from_target_files', 'md5sum', 'timestamp', 'to_target_files'])
.help('help').alias('help', 'h')
.argv;
function createNewIncremental(sourceRom, targetRom) {
var buildTimestamp = utils.toDate(buildInfo.timestamp);
var filesize = null;
if (buildInfo.filesize && !isNaN(buildInfo.filesize)) {
filesize = buildInfo.filesize;
}
models.Incremental.build({
RomVariantId: sourceRom.RomVariantId,
sourceRomId: sourceRom.id,
targetRomId: targetRom.id,
timestamp: buildTimestamp,
md5sum: buildInfo.md5sum,
filename: buildInfo.filename,
isActive: buildInfo.active == true,
fileSize: filesize,
}).save().then(function(newRom) {
console.log('Successfully created new incremental: ' + JSON.stringify(newRom));
});
}
var findRomWithTargetFilesZipName = function(targetFilesZipName, subdirectory) {
return models.Rom.find({
where: {
targetFilesZipName: targetFilesZipName,
},
include: [
{
// Device is implicitly part of the targetFilesZipName.
model: models.RomVariant,
where: {
subdirectory: subdirectory,
}
}
]
});
}
utils.rethrowUnhandledPromiseRejections();
models.sequelize.sync().then(function() {
findRomWithTargetFilesZipName(buildInfo.from_target_files, buildInfo.subdirectory).then(function(sourceRom) {
if (sourceRom) {
findRomWithTargetFilesZipName(buildInfo.to_target_files, buildInfo.subdirectory).then(function(targetRom) {
if (targetRom) {
createNewIncremental(sourceRom, targetRom);
} else {
console.log('Target rom with targetFilesZipName "%s" not found.', buildInfo.to_target_files);
}
});
} else {
console.log('Source rom with targetFilesZipName "%s" not found.', buildInfo.from_target_files);
}
});
});