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-build.js
141 lines (123 loc) · 4.79 KB
/
add-build.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
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
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 build to the database.')
.alias('active', 'A').boolean('active').describe('active', 'Marks the build as active (available for download) or not.')
.alias('api_level', 'a').nargs('api_level', 1).number('api_level').describe('api_level', 'The SDK API-level of the ROM ("ro.build.version.sdk").')
.alias('changelogfile', 'C').nargs('changelogfile', 1).describe('changelogfile', 'A path to a file which contains the changelog (utf-8 encoded) for the build.')
.alias('channel', 'c').nargs('channel', 1).describe('channel', 'The update-channel.')
.alias('device', 'd').nargs('device', 1).describe('device', 'The device ID.')
.alias('filename', 'f').nargs('filename', 1).describe('filename', 'The resulting filename.')
.alias('filesize', 'F').nargs('filesize', 1).number('filesize').describe('filesize', 'The size (in bytes) of the ZIP file.')
.alias('incrementalid', 'i').nargs('incrementalid', 1).describe('incrementalid', 'The build\'s incremental ID ("ro.build.version.incremental").')
.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('sourcecode_timestamp', 'S').nargs('sourcecode_timestamp', 1).number('sourcecode_timestamp').describe('sourcecode_timestamp', 'The ("unixepoch") timestamp when the source code was updated.')
.alias('targetfileszip', 'T').nargs('targetfileszip', 1).describe('targetfileszip', 'The name of the "target files" ZIP archive (useful for generating incremental updates).')
.alias('timestamp', 't').nargs('timestamp', 1).number('timestamp').describe('timestamp', 'The build\'s timestamp as "unixepoch" timestamp ("ro.build.date.utc").')
.demandOption(['api_level', 'active', 'channel', 'device', 'filename', 'md5sum', 'timestamp'])
.help('help').alias('help', 'h')
.argv;
function createNewRomVariantFor(device) {
var variantName = device.name + '_' + buildInfo.api_level + '_' + buildInfo.channel.toLowerCase();
var romVariant = models.RomVariant.build({
DeviceId: device.id,
name: variantName,
subdirectory: buildInfo.subdirectory,
});
romVariant.save().then(function() {
console.log('Successfully created new rom variant ' + JSON.stringify(romVariant));
createNewRomFor(romVariant, null);
});
}
function createNewRomFor(romVariant, parentRom) {
var buildTimestamp = utils.toDate(buildInfo.timestamp);
var parsedUpdateChannel = new String(buildInfo.channel);
if (parsedUpdateChannel.toUpperCase() == "RC") {
parsedUpdateChannel = "RC";
} else {
parsedUpdateChannel = parsedUpdateChannel.toLowerCase();
}
var sourceCodeTimestamp = null;
if (buildInfo.sourcecode_timestamp && buildInfo.sourcecode_timestamp > 0) {
sourceCodeTimestamp = utils.toDate(buildInfo.sourcecode_timestamp);
}
var filesize = null;
if (buildInfo.filesize && !isNaN(buildInfo.filesize)) {
filesize = buildInfo.filesize;
}
var parentRomId = null;
if (parentRom) {
parentRomId = parentRom.id;
}
models.Rom.build({
RomVariantId: romVariant.id,
timestamp: buildTimestamp,
md5sum: buildInfo.md5sum,
filename: buildInfo.filename,
updateChannel: parsedUpdateChannel,
changelog: changelog,
apiLevel: buildInfo.api_level,
isActive: buildInfo.active,
sourceCodeTimestamp: sourceCodeTimestamp,
incrementalId: buildInfo.incrementalid,
parentRomId: parentRomId,
targetFilesZipName: buildInfo.targetfileszip,
fileSize: filesize,
}).save().then(function(newRom) {
console.log('Successfully created new rom: ' + JSON.stringify(newRom));
});
}
var changelog = null;
if (buildInfo.changelogfile) {
changelog = fs.readFileSync(buildInfo.changelogfile, 'utf-8');
}
utils.rethrowUnhandledPromiseRejections();
models.sequelize.sync().then(function() {
models.RomVariant.find({
include: [
{
model: models.Device,
where: {
name: buildInfo.device,
}
},
],
where: {
subdirectory: buildInfo.subdirectory
}
}).then(function(romVariant) {
if (romVariant) {
models.Rom.find({
include: [
{
model: models.RomVariant,
where: {
id: romVariant.id,
}
}
],
order: 'timestamp DESC'
}).then(function(parentRom) {
createNewRomFor(romVariant, parentRom);
});
} else {
models.Device.find({
where: {
name: buildInfo.device
}
}).then(function(device) {
if (device) {
createNewRomVariantFor(device);
} else {
var device = models.Device.build({ name: buildInfo.device });
device.save().then(function() {
console.log('Successfully created new device ' + JSON.stringify(device));
createNewRomVariantFor(device);
});
}
});
}
});
});