Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

Commit

Permalink
port cm-update-server from Troll-opt to yargs
Browse files Browse the repository at this point in the history
Troll-opt is not maintained actively anymore and does not work with
recent versions of NodeJS 4 or NodeJS 6. Porting cm-update-server to
yargs fixes these compatibility issues.
There should be no functional changes with this patch.

This fixes #9
  • Loading branch information
xdarklight committed Feb 19, 2017
1 parent 467cc23 commit 8757ee0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 51 deletions.
36 changes: 19 additions & 17 deletions add-build.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
var Troll = require('troll-opt').Troll;
var models = require('./models/');
var fs = require('fs');
var utils = require('./utils.js');

var buildInfo = (new Troll()).options(function(troll) {
troll.banner('Adds a new build to the database.');
troll.opt('device', 'The device ID.', { type: 'string', required: true });
troll.opt('timestamp', 'The build\'s timestamp as "unixepoch" timestamp ("ro.build.date.utc").', { type: 'integer', required: true });
troll.opt('md5sum', 'The build\'s md5sum.', { type: 'string', required: true });
troll.opt('filename', 'The resulting filename.', { type: 'string', required: true });
troll.opt('channel', 'The update-channel.', { type: 'string', required: true });
troll.opt('api_level', 'The SDK API-level of the ROM ("ro.build.version.sdk").', { type: 'integer', required: true });
troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' });
troll.opt('active', 'Marks the build as active (available for download) or not.', { type: 'boolean', required: true });
troll.opt('sourcecode_timestamp', 'The ("unixepoch") timestamp when the source code was updated.', { type: 'integer' });
troll.opt('filesize', 'The size (in bytes) of the ZIP file.', { type: 'integer' });
troll.opt('incrementalid', 'The build\s incremental ID ("ro.build.version.incremental").', { type: 'string' });
troll.opt('changelogfile', 'A path to a file which contains the changelog (utf-8 encoded) for the build.', { type: 'string' });
troll.opt('targetfileszip', 'The name of the "target files" ZIP archive (useful for generating incremental updates).', { type: 'string' });
});
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 + '_' + new Date().getTime();
Expand Down
25 changes: 13 additions & 12 deletions add-incremental.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
var Troll = require('troll-opt').Troll;
var models = require('./models/');
var fs = require('fs');
var utils = require('./utils.js');

var buildInfo = (new Troll()).options(function(troll) {
troll.banner('Adds a new incremental build to the database.');
troll.opt('timestamp', 'The build\'s timestamp as "unixepoch" timestamp ("ro.build.date.utc").', { type: 'integer', required: true });
troll.opt('md5sum', 'The build\'s md5sum.', { type: 'string', required: true });
troll.opt('filename', 'The resulting filename.', { type: 'string', required: true });
troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' });
troll.opt('from_target_files', 'The name of the "target files ZIP" of the incremental\'s "source".', { type: 'string', required: true });
troll.opt('to_target_files', 'The name of the "target files ZIP" of the incremental\'s "target".', { type: 'string', required: true });
troll.opt('active', 'Marks the incremental as active (available for download) or not.', { type: 'boolean', required: true });
troll.opt('filesize', 'The size (in bytes) of the incremental update file.', { type: 'integer' });
});
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);
Expand Down
17 changes: 9 additions & 8 deletions disable-build.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
var Troll = require('troll-opt').Troll;
var models = require('./models/');
var utils = require('./utils.js');

var buildInfo = (new Troll()).options(function(troll) {
troll.banner('Marks a build as disabled so it cannot be downloaded anymore.');
troll.opt('device', 'The device ID.', { type: 'string', required: true });
troll.opt('filename', 'The resulting filename.', { type: 'string', required: true });
troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' });
troll.opt('disable_incrementals', 'Disables the incrementals for this rom also.', { type: 'boolean' });
});
var buildInfo = require('yargs')
.usage('Usage: $0 [options]\n Marks a build as disabled so it cannot be downloaded anymore.')
.alias('device', 'd').nargs('device', 1).describe('device', 'The device ID.')
.alias('disable_incrementals', 'D').boolean('disable_incrementals').describe('disable_incrementals', 'Disables the incrementals for this rom also.')
.alias('filename', 'f').nargs('filename', 1).describe('filename', 'The resulting filename.')
.alias('subdirectory', 's').nargs('subdirectory', 1).describe('subdirectory', 'The subdirectory from which the file can be downloaded.')
.demandOption(['device', 'filename'])
.help('help').alias('help', 'h')
.argv;

utils.rethrowUnhandledPromiseRejections();

Expand Down
13 changes: 7 additions & 6 deletions get-sourcecode-timestamp.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
var Troll = require('troll-opt').Troll;
var models = require('./models/');
var utils = require('./utils.js');

var buildInfo = (new Troll()).options(function(troll) {
troll.banner('Outputs the newest source-code as ISO-8601 string for the given device / subdirectory.');
troll.opt('device', 'The device ID.', { type: 'string', required: true });
troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' });
});
var buildInfo = require('yargs')
.usage('Usage: $0 [options]\n Outputs the newest source-code as ISO-8601 string for the given device / subdirectory.')
.alias('device', 'd').nargs('device', 1).describe('device', 'The device ID.')
.alias('subdirectory', 's').nargs('subdirectory', 1).describe('subdirectory', 'The subdirectory from which the file can be downloaded.')
.demandOption(['device'])
.help('help').alias('help', 'h')
.argv;

utils.rethrowUnhandledPromiseRejections();

Expand Down
16 changes: 9 additions & 7 deletions get-target-file-zipnames.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
var Troll = require('troll-opt').Troll;
var models = require('./models/');
var utils = require('./utils.js');

var buildInfo = (new Troll()).options(function(troll) {
troll.banner('Outputs all target-files zip names (one per line) for all builds that match the given device / subdirectory.');
troll.opt('device', 'The device ID.', { type: 'string', required: true });
troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' });
troll.opt('max_age_days', 'The max age (according to a Rom\' timestamp) of the target files in days.', { type: 'integer' });
});
var buildInfo = require('yargs')
.usage('Usage: $0 [options]\n Outputs all target-files zip names (one per line) for all builds that match the given device / subdirectory.')
.alias('device', 'd').nargs('device', 1).describe('device', 'The device ID.')
.alias('max_age_days', 'max_age_days').nargs('max_age_days', 1).number('max_age_days').describe('max_age_days', 'The max age (according to a Rom\'s timestamp) of the target files in days.')
.alias('subdirectory', 's').nargs('subdirectory', 1).describe('subdirectory', 'The subdirectory from which the file can be downloaded.')
.demandOption(['device'])
.help('help').alias('help', 'h')
.argv;


var minDate = new Date(-8640000000000000);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},

"dependencies": {
"troll-opt" : "^0.7.0",
"yargs" : "^6.6.0",
"config": "^1.24.0",
"restify": "^4.2.0",
"sequelize-cli": "^2.4.0",
Expand Down

0 comments on commit 8757ee0

Please sign in to comment.