@enplug/scripts 1.11.4 → 1.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/build-legacy.js +0 -0
- package/bin/build-ng.js +0 -0
- package/bin/check-packages.js +0 -0
- package/bin/functions/translations/crowdin.js +137 -77
- package/bin/functions/translations/translations.js +73 -8
- package/bin/release-i18n.js +0 -0
- package/bin/release-legacy.js +0 -0
- package/bin/release-ng.js +0 -0
- package/bin/release-sdk.js +0 -0
- package/bin/serve-ng.js +0 -0
- package/enplug_device/commands.py +22 -22
- package/enplug_device/enplug_device.py +256 -256
- package/package.json +1 -1
package/bin/build-legacy.js
CHANGED
|
File without changes
|
package/bin/build-ng.js
CHANGED
|
File without changes
|
package/bin/check-packages.js
CHANGED
|
File without changes
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const axios = require('axios');
|
|
2
2
|
const chalk = require('chalk');
|
|
3
3
|
const fs = require('fs');
|
|
4
|
-
const FormData = require('form-data');
|
|
5
4
|
const inquirer = require('inquirer');
|
|
6
5
|
const loadDevPrivateFile = require('../loadDevPrivateFile');
|
|
7
6
|
const rootPath = __dirname.split('node_modules')[0];
|
|
@@ -13,59 +12,9 @@ const { catchError, switchMap, tap, filter } = require('rxjs/operators');
|
|
|
13
12
|
const HTTP_UNAUTHORIZED_STATUS_CODE = 401;
|
|
14
13
|
const HTTP_NOT_FOUND_STATUS_CODE = 404;
|
|
15
14
|
|
|
16
|
-
const CROWDIN_PROJECT_ID = '
|
|
17
|
-
const CROWDIN_PROJECT_URL = `https://api.crowdin.com/api/
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
async function uploadFileToCrowdin(credentials, crowdinPath, localPath) {
|
|
21
|
-
if (!credentials || !credentials.login || !credentials.accountKey) {
|
|
22
|
-
console.error(`${chalk.red.bold('Crowdin credentials not provided')}`);
|
|
23
|
-
console.log(`Make sure that the ${chalk.default.yellow('dev.private.json')} file contains ${chalk.default.yellow('crowdinCredentials: { login, accountKey }')}`);
|
|
24
|
-
throw new Error('Crowdin credentials not provided');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!fs.existsSync(localPath)) {
|
|
28
|
-
console.error(`${chalk.red.bold('Local file does not exists')} ${chalk.yellow.bold(`[${localPath}]`)}`);
|
|
29
|
-
throw new Error('Local file does not exist');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return postFileToCrowdin('update', credentials, crowdinPath, localPath).pipe(
|
|
33
|
-
catchError(error => {
|
|
34
|
-
if (error.response.status === HTTP_NOT_FOUND_STATUS_CODE) {
|
|
35
|
-
return promptAddFile(crowdinPath).pipe(
|
|
36
|
-
filter(({addFileConfirm}) => addFileConfirm === true),
|
|
37
|
-
switchMap(() => postFileToCrowdin('add', credentials, crowdinPath, localPath))
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return throwError(error);
|
|
42
|
-
}),
|
|
43
|
-
tap({
|
|
44
|
-
next: response => {
|
|
45
|
-
if (response.data.success) {
|
|
46
|
-
console.log(`${chalk.green.bold('Translations uploaded to Crowdin')} ${chalk.yellow.bold(`[${crowdinPath}]`)}`);
|
|
47
|
-
} else {
|
|
48
|
-
console.error('Unexpected result');
|
|
49
|
-
console.log(response);
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
error: error => {
|
|
53
|
-
const crowdinError = error.response && error.response.data && error.response.data.error;
|
|
54
|
-
|
|
55
|
-
if (crowdinError && crowdinError.code === CROWDIN_DIRECTORY_NOT_FOUND_ERROR_CODE) {
|
|
56
|
-
console.error(`\n${chalk.red.bold('Directory does not exist')} ${chalk.yellow.bold(`[${crowdinPath}]`)}`);
|
|
57
|
-
console.log('Create the directory in the Crowdin panel first.');
|
|
58
|
-
} else if (error.response.status === HTTP_UNAUTHORIZED_STATUS_CODE) {
|
|
59
|
-
console.error(`\n${chalk.red.bold('Provided Crowdin credentials are incorrect')}`);
|
|
60
|
-
console.log(`Check the ${chalk.default.yellow('dev.private.json')} file.`);
|
|
61
|
-
} else {
|
|
62
|
-
console.error('\nUnexpected error:');
|
|
63
|
-
console.error(error);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
).toPromise();
|
|
68
|
-
}
|
|
15
|
+
const CROWDIN_PROJECT_ID = '401630';
|
|
16
|
+
const CROWDIN_PROJECT_URL = `https://api.crowdin.com/api/v2/projects/${CROWDIN_PROJECT_ID}`;
|
|
17
|
+
const CROWDIN_STORAGE_URL = `https://api.crowdin.com/api/v2/storages`;
|
|
69
18
|
|
|
70
19
|
function getCrowdinCredentials() {
|
|
71
20
|
try {
|
|
@@ -105,38 +54,149 @@ function getCrowdinConfig() {
|
|
|
105
54
|
return pkg.config.crowdin;
|
|
106
55
|
}
|
|
107
56
|
|
|
108
|
-
function
|
|
109
|
-
|
|
57
|
+
async function findCrowdinAppDirectoryId(credentials, crowdinPath, appName) {
|
|
58
|
+
try {
|
|
59
|
+
if(crowdinPath.startsWith('apps') || appName !== 'en.json') { // path is apps/{app-name}/... or dashboard/{data-connector or regions-map or uploader}/en.json
|
|
60
|
+
const url = `${CROWDIN_PROJECT_URL}/directories?filter=${appName}`;
|
|
61
|
+
const AuthStr = 'Bearer '.concat(credentials.token);
|
|
62
|
+
const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
|
|
63
|
+
const directory = resp.data.data.find(d => d.data.name === appName );
|
|
64
|
+
return directory ? directory.data.id : undefined;
|
|
65
|
+
} else if((crowdinPath.startsWith('dashboard') || crowdinPath.startsWith('player-web') || crowdinPath.startsWith('components')) && appName === 'en.json') { //path is dashboard/en.json or player-web/en.json or components/en.json
|
|
66
|
+
const url = `${CROWDIN_PROJECT_URL}/directories?filter=dashboard`;
|
|
67
|
+
const AuthStr = 'Bearer '.concat(credentials.token);
|
|
68
|
+
const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
|
|
69
|
+
const directory = resp.data.data.find(d => d.data.name === 'dashboard' && d.data.title === 'Dashboard' && d.data.path === '/dashboard');
|
|
70
|
+
return directory ? directory.data.id : undefined;
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
if (err.response.status === HTTP_UNAUTHORIZED_STATUS_CODE) {
|
|
74
|
+
console.error(`\n${chalk.red.bold('Provided Crowdin token is invalid')}`);
|
|
75
|
+
console.log(`Check the ${chalk.default.yellow('dev.private.json')} file.`);
|
|
76
|
+
return throwError(err);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
110
80
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
81
|
+
async function findCrowdinAppSubFolderId(credentials, directoryId, subfolderName) {
|
|
82
|
+
const url = `${CROWDIN_PROJECT_URL}/directories?directoryId=${directoryId}`;
|
|
83
|
+
const AuthStr = 'Bearer '.concat(credentials.token);
|
|
84
|
+
const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
|
|
85
|
+
const subdirectory = resp.data.data.find(d => d.data.name === subfolderName);
|
|
86
|
+
return subdirectory ? subdirectory.data.id : undefined;
|
|
87
|
+
}
|
|
117
88
|
|
|
118
|
-
|
|
89
|
+
async function getFileIdIfExists(credentials, directoryId, fileName) {
|
|
90
|
+
const url = `${CROWDIN_PROJECT_URL}/files?directoryId=${directoryId}`;
|
|
91
|
+
const AuthStr = 'Bearer '.concat(credentials.token);
|
|
92
|
+
const resp = await axios.get(url, { headers: { Authorization: AuthStr } });
|
|
93
|
+
const file = resp.data.data.find(d => d.data.name === fileName);
|
|
94
|
+
return file ? file.data.id : undefined;
|
|
119
95
|
}
|
|
120
96
|
|
|
121
|
-
function postFileToCrowdin(
|
|
122
|
-
const
|
|
97
|
+
function postFileToCrowdin(credentials, localPath) {
|
|
98
|
+
const AuthStr = 'Bearer '.concat(credentials.token);
|
|
99
|
+
const file = fs.readFileSync(localPath);
|
|
100
|
+
const url = `${CROWDIN_STORAGE_URL}`;
|
|
101
|
+
|
|
102
|
+
return from(axios.post(url, file, { headers: {
|
|
103
|
+
"Authorization": AuthStr,
|
|
104
|
+
"Content-Type": 'application/json',
|
|
105
|
+
"Crowdin-API-FileName": 'en.json'
|
|
106
|
+
} }));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function uploadFileToCrowdinStorage(credentials, localPath) {
|
|
110
|
+
if (!fs.existsSync(localPath)) {
|
|
111
|
+
console.error(`${chalk.red.bold('Local file does not exists')} ${chalk.yellow.bold(`[${localPath}]`)}`);
|
|
112
|
+
throw new Error('Local file does not exist');
|
|
113
|
+
}
|
|
114
|
+
return postFileToCrowdin(credentials, localPath).pipe(
|
|
115
|
+
catchError(error => {
|
|
116
|
+
console('ERROR could not upload file to crowdin storage')
|
|
117
|
+
return throwError(error);
|
|
118
|
+
}),
|
|
119
|
+
).toPromise();
|
|
120
|
+
}
|
|
123
121
|
|
|
124
|
-
|
|
125
|
-
const url = `${CROWDIN_PROJECT_URL}/${
|
|
122
|
+
async function updateCrowdinFile(credentials, crowdinPath, storageId, fileId) {
|
|
123
|
+
const url = `${CROWDIN_PROJECT_URL}/files/${fileId}`;
|
|
124
|
+
const AuthStr = 'Bearer '.concat(credentials.token);
|
|
125
|
+
const body = {
|
|
126
|
+
"storageId": storageId,
|
|
127
|
+
"updateOption": "keep_translations_and_approvals",
|
|
128
|
+
"importOptions": {
|
|
129
|
+
"contentSegmentation": false,
|
|
130
|
+
"customSegmentation": false
|
|
131
|
+
},
|
|
132
|
+
"exportOptions": {
|
|
133
|
+
"exportPattern": "%locale%.json"
|
|
134
|
+
},
|
|
135
|
+
"replaceModifiedContext": false
|
|
136
|
+
}
|
|
137
|
+
return from(axios.put(url, body, { headers: { Authorization: AuthStr } })).pipe(tap({
|
|
138
|
+
next: response => {
|
|
139
|
+
if (response.data) {
|
|
140
|
+
console.log(`${chalk.green.bold('Translations uploaded to Crowdin')} ${chalk.yellow.bold(`[${crowdinPath}]`)}`);
|
|
141
|
+
} else {
|
|
142
|
+
console.error('Unexpected result');
|
|
143
|
+
console.log(response);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
error: error => {
|
|
147
|
+
console.error('\nUnexpected error:');
|
|
148
|
+
console.error(error);
|
|
149
|
+
}
|
|
150
|
+
})).toPromise();
|
|
151
|
+
}
|
|
126
152
|
|
|
127
|
-
|
|
153
|
+
async function addCrowdinFile(credentials, crowdinPath, storageId, folderId) {
|
|
154
|
+
const url = `${CROWDIN_PROJECT_URL}/files`;
|
|
155
|
+
const AuthStr = 'Bearer '.concat(credentials.token);
|
|
156
|
+
const body = {
|
|
157
|
+
"storageId": storageId,
|
|
158
|
+
"name": "en.json",
|
|
159
|
+
"directoryId": folderId,
|
|
160
|
+
"context": null,
|
|
161
|
+
"type": "json",
|
|
162
|
+
"parserVersion": 1,
|
|
163
|
+
"importOptions": {
|
|
164
|
+
"contentSegmentation": false,
|
|
165
|
+
"customSegmentation": false
|
|
166
|
+
},
|
|
167
|
+
"exportOptions": {
|
|
168
|
+
"exportPattern": "%locale%.json"
|
|
169
|
+
},
|
|
170
|
+
"excludedTargetLanguages": null
|
|
171
|
+
}
|
|
172
|
+
return from(axios.post(url, body, { headers: { Authorization: AuthStr } })).pipe(tap({
|
|
173
|
+
next: response => {
|
|
174
|
+
if (response.data) {
|
|
175
|
+
console.log(`${chalk.green.bold('Translations uploaded to Crowdin')} ${chalk.yellow.bold(`[${crowdinPath}]`)}`);
|
|
176
|
+
} else {
|
|
177
|
+
console.error('Unexpected result');
|
|
178
|
+
console.log(response);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
error: error => {
|
|
182
|
+
console.error('\nUnexpected error:');
|
|
183
|
+
console.error(error);
|
|
184
|
+
}
|
|
185
|
+
})).toPromise();
|
|
128
186
|
}
|
|
129
187
|
|
|
130
|
-
function fetchFileFromCrowdin(credentials,
|
|
131
|
-
const url = `${CROWDIN_PROJECT_URL}/
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
'language': language
|
|
188
|
+
function fetchFileFromCrowdin(credentials, language, fileId) {
|
|
189
|
+
const url = `${CROWDIN_PROJECT_URL}/translations/exports`;
|
|
190
|
+
const AuthStr = 'Bearer '.concat(credentials.token);
|
|
191
|
+
const body = {
|
|
192
|
+
"targetLanguageId": language,
|
|
193
|
+
"fileIds": [fileId]
|
|
137
194
|
};
|
|
195
|
+
return axios.post(url, body, { headers: { Authorization: AuthStr } });
|
|
196
|
+
}
|
|
138
197
|
|
|
139
|
-
|
|
198
|
+
function readFakeTranslationsFile(url) {
|
|
199
|
+
return axios.get(url);
|
|
140
200
|
}
|
|
141
201
|
|
|
142
202
|
function promptAddFile(crowdinPath) {
|
|
@@ -149,4 +209,4 @@ function promptAddFile(crowdinPath) {
|
|
|
149
209
|
}));
|
|
150
210
|
}
|
|
151
211
|
|
|
152
|
-
module.exports = { getCrowdinCredentials, getCrowdinConfig,
|
|
212
|
+
module.exports = { getCrowdinCredentials, getCrowdinConfig, findCrowdinAppDirectoryId, findCrowdinAppSubFolderId, getFileIdIfExists, uploadFileToCrowdinStorage, updateCrowdinFile, addCrowdinFile, fetchFileFromCrowdin, readFakeTranslationsFile };
|
|
@@ -5,7 +5,7 @@ const inquirer = require('inquirer');
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const path = require('path');
|
|
7
7
|
|
|
8
|
-
const { getCrowdinCredentials, getCrowdinConfig,
|
|
8
|
+
const { getCrowdinCredentials, getCrowdinConfig, findCrowdinAppDirectoryId, findCrowdinAppSubFolderId, getFileIdIfExists, uploadFileToCrowdinStorage, updateCrowdinFile, addCrowdinFile, fetchFileFromCrowdin, readFakeTranslationsFile } = require('./crowdin');
|
|
9
9
|
const { checkKeys, validateTranslationFile } = require('./transloco');
|
|
10
10
|
const { uploadTranslationToS3 } = require('./translation-s3');
|
|
11
11
|
const getPackageJson = require('../getPackageJson');
|
|
@@ -43,6 +43,12 @@ async function syncTranslations(s3Client, bucket) {
|
|
|
43
43
|
config = getCrowdinConfig();
|
|
44
44
|
} catch {}
|
|
45
45
|
|
|
46
|
+
if (!credentials || !credentials.token) {
|
|
47
|
+
console.error(`${chalk.red.bold('Crowdin credentials not provided')}`);
|
|
48
|
+
console.log(`Make sure that the ${chalk.default.yellow('dev.private.json')} file contains ${chalk.default.yellow('crowdinCredentials: { token }')}`);
|
|
49
|
+
throw new Error('Crowdin credentials not provided');
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
if (credentials && config) {
|
|
47
53
|
const { confirmUpload } = await promptUpload(config.crowdinPath, isProduction);
|
|
48
54
|
|
|
@@ -55,18 +61,77 @@ async function syncTranslations(s3Client, bucket) {
|
|
|
55
61
|
await uploadTranslationToS3(s3Client, bucket, s3EnPath, enTranslation);
|
|
56
62
|
|
|
57
63
|
if (isProduction) {
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
const crowdinPath = config.crowdinPath.startsWith('/') ? config.crowdinPath.substr(1) : config.crowdinPath;
|
|
65
|
+
const crowdinPathSections = crowdinPath.split('/');
|
|
66
|
+
const appName = crowdinPathSections[1];
|
|
67
|
+
const appDirectoryId = await findCrowdinAppDirectoryId(credentials, crowdinPath, appName);
|
|
68
|
+
if(appDirectoryId === undefined) {
|
|
69
|
+
console.error(`\n${chalk.red.bold('Directory does not exist')} ${chalk.yellow.bold(`${appName}`)}`);
|
|
70
|
+
console.log('Create the directory in the Crowdin panel first.');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if(crowdinPathSections[0] === 'apps' && appDirectoryId) {
|
|
74
|
+
if(crowdinPathSections.length !== 4 && crowdinPathSections[3] !== 'en.json') {
|
|
75
|
+
console.error(`\n${chalk.red.bold('Crowdin path provided does not match defined format, make sure the path is as follows /apps/{app-id}/dashboard/en.json or /apps/{app-id}/app/en.json')}`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const subfolderName = crowdinPathSections[2]; //dashboard or app folder
|
|
79
|
+
const folderId = await findCrowdinAppSubFolderId(credentials, appDirectoryId, subfolderName);
|
|
80
|
+
if(folderId === undefined) {
|
|
81
|
+
console.error(`Could not find ${chalk.yellow.bold(`[${subfolderName}]`)} folder`);
|
|
82
|
+
}
|
|
83
|
+
const fileId = await getFileIdIfExists(credentials, folderId, crowdinPathSections[3]); // en.json file id to update
|
|
84
|
+
if(fileId) {
|
|
85
|
+
const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
|
|
86
|
+
if(fileId && storageId) {
|
|
87
|
+
await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
|
|
88
|
+
await updateFrakeTranslations(credentials, fileId, s3EnPath, s3Client, bucket);
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
|
|
92
|
+
if(storageId) {
|
|
93
|
+
const result = await addCrowdinFile(credentials, crowdinPath, storageId.data.data.id, folderId);
|
|
94
|
+
await updateFrakeTranslations(credentials, result.data.data.id, s3EnPath, s3Client, bucket);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} else if((crowdinPathSections[0] === 'dashboard' || crowdinPathSections[0] === 'player-web' || crowdinPathSections[0] === 'components') && appDirectoryId) {
|
|
98
|
+
if(crowdinPathSections[1] === 'en.json') {
|
|
99
|
+
const fileId = await getFileIdIfExists(credentials, appDirectoryId, crowdinPathSections[1]); // en.json file id to update
|
|
100
|
+
if(fileId) {
|
|
101
|
+
const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
|
|
102
|
+
if(fileId && storageId) {
|
|
103
|
+
await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
|
|
104
|
+
await updateFrakeTranslations(credentials, fileId, s3EnPath, s3Client, bucket);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
console.error(`Could not upload ${chalk.yellow.bold(`${rowdinPathSections[1]}`)}. Only en.json supported.`);
|
|
108
|
+
}
|
|
109
|
+
} else { // data-connector, regions-map and uploader in dashboard folder
|
|
110
|
+
const folderId = await findCrowdinAppDirectoryId(credentials, crowdinPath, crowdinPathSections[1]);
|
|
111
|
+
if(folderId === undefined) {
|
|
112
|
+
console.error(`Could not find ${chalk.yellow.bold(`${folderId}`)} folder`);
|
|
113
|
+
}
|
|
114
|
+
const fileId = await getFileIdIfExists(credentials, folderId, crowdinPathSections[2]); // en.json file id to update
|
|
115
|
+
const storageId = await uploadFileToCrowdinStorage(credentials, config.localPath);
|
|
116
|
+
if(fileId && storageId) {
|
|
117
|
+
await updateCrowdinFile(credentials, crowdinPath, storageId.data.data.id, fileId);
|
|
118
|
+
await updateFrakeTranslations(credentials, fileId, s3EnPath, s3Client, bucket);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
65
122
|
}
|
|
66
123
|
}
|
|
67
124
|
}
|
|
68
125
|
}
|
|
69
126
|
|
|
127
|
+
async function updateFrakeTranslations(credentials, fileId, s3EnPath, s3Client, bucket) {
|
|
128
|
+
const { data: fakeTranslationUrl } = await fetchFileFromCrowdin(credentials, FAKE_IN_CONTEXT_LANGUAGE, fileId);
|
|
129
|
+
const s3TranslationsPath = path.parse(s3EnPath).dir;
|
|
130
|
+
const s3FakeTranslationPath = path.join(s3TranslationsPath, FAKE_IN_CONTEXT_LANGUAGE_FILE);
|
|
131
|
+
const fakeTranslation = await readFakeTranslationsFile(fakeTranslationUrl.data.url);
|
|
132
|
+
await uploadTranslationToS3(s3Client, bucket, s3FakeTranslationPath, JSON.stringify(fakeTranslation.data));
|
|
133
|
+
}
|
|
134
|
+
|
|
70
135
|
async function promptForceContinue() {
|
|
71
136
|
return inquirer.prompt({
|
|
72
137
|
type: 'confirm',
|
package/bin/release-i18n.js
CHANGED
|
File without changes
|
package/bin/release-legacy.js
CHANGED
|
File without changes
|
package/bin/release-ng.js
CHANGED
|
File without changes
|
package/bin/release-sdk.js
CHANGED
|
File without changes
|
package/bin/serve-ng.js
CHANGED
|
File without changes
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
# sqs_is_prod = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"select * from Settings;\""
|
|
3
|
-
adb_devices = "adb devices"
|
|
4
|
-
build_binary = "pyinstaller --onefile enplug_device.py --distpath ../bin/"
|
|
5
|
-
change_env_to_development = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from settings where key='eduid';delete from settings where key='eduid';delete from settings where key='edutoken';delete from settings where key='eduname';insert into settings (key, value) values ('environment', 'development');update settings set value='development' where key='environment';\""
|
|
6
|
-
change_env_to_production = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from settings where key='eduid';delete from settings where key='eduid';delete from settings where key='edutoken';delete from settings where key='eduname';insert into settings (key, value) values ('environment', 'development');update settings set value='development' where key='environment';\""
|
|
7
|
-
change_env_to_staging = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from settings where key='eduid';delete from settings where key='eduid';delete from settings where key='edutoken';delete from settings where key='eduname';insert into settings (key, value) values ('environment', 'staging');update settings set value='staging' where key='environment';\""
|
|
8
|
-
clear_cache = "adb shell pm clear com.enplug.player"
|
|
9
|
-
copy_player_file_to_device = "adb push Player.apk '/sdcard/Download'"
|
|
10
|
-
disable_webview = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='UseWebView'; insert into Settings values ('UseWebView', 'false');\""
|
|
11
|
-
enable_web_debugger = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"insert into settings values('WebRemoteDebugging','true')\""
|
|
12
|
-
enable_webview = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='UseWebView'; insert into Settings values ('UseWebView', 'true');\""
|
|
13
|
-
get_environment = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"select value from Settings where key='environment';\""
|
|
14
|
-
install_package = "adb install Player.apk"
|
|
15
|
-
logs_delete_all = "adb shell rm /sdcard/LogWriter/*"
|
|
16
|
-
make_sdcard_writable = "adb shell mount -o rw,remount rootfs /"
|
|
17
|
-
reboot = "adb shell reboot"
|
|
18
|
-
set_zoning_version_development = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='ZoningHostUrl'; insert into Settings values ('ZoningHostUrl', 'https://dev-player.enplug.in/{0}/');\""
|
|
19
|
-
set_zoning_version_production = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='ZoningHostUrl'; insert into Settings values ('ZoningHostUrl', 'https://player.enplug.com/{0}/');\""
|
|
20
|
-
set_zoning_version_staging = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='ZoningHostUrl'; insert into Settings values ('ZoningHostUrl', 'https://player.enplug.in/{0}/');\""
|
|
21
|
-
show_settings="adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"select * from Settings;\""
|
|
22
|
-
uninstall_package = "adb uninstall com.enplug.player"
|
|
1
|
+
|
|
2
|
+
# sqs_is_prod = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"select * from Settings;\""
|
|
3
|
+
adb_devices = "adb devices"
|
|
4
|
+
build_binary = "pyinstaller --onefile enplug_device.py --distpath ../bin/"
|
|
5
|
+
change_env_to_development = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from settings where key='eduid';delete from settings where key='eduid';delete from settings where key='edutoken';delete from settings where key='eduname';insert into settings (key, value) values ('environment', 'development');update settings set value='development' where key='environment';\""
|
|
6
|
+
change_env_to_production = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from settings where key='eduid';delete from settings where key='eduid';delete from settings where key='edutoken';delete from settings where key='eduname';insert into settings (key, value) values ('environment', 'development');update settings set value='development' where key='environment';\""
|
|
7
|
+
change_env_to_staging = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from settings where key='eduid';delete from settings where key='eduid';delete from settings where key='edutoken';delete from settings where key='eduname';insert into settings (key, value) values ('environment', 'staging');update settings set value='staging' where key='environment';\""
|
|
8
|
+
clear_cache = "adb shell pm clear com.enplug.player"
|
|
9
|
+
copy_player_file_to_device = "adb push Player.apk '/sdcard/Download'"
|
|
10
|
+
disable_webview = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='UseWebView'; insert into Settings values ('UseWebView', 'false');\""
|
|
11
|
+
enable_web_debugger = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"insert into settings values('WebRemoteDebugging','true')\""
|
|
12
|
+
enable_webview = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='UseWebView'; insert into Settings values ('UseWebView', 'true');\""
|
|
13
|
+
get_environment = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"select value from Settings where key='environment';\""
|
|
14
|
+
install_package = "adb install Player.apk"
|
|
15
|
+
logs_delete_all = "adb shell rm /sdcard/LogWriter/*"
|
|
16
|
+
make_sdcard_writable = "adb shell mount -o rw,remount rootfs /"
|
|
17
|
+
reboot = "adb shell reboot"
|
|
18
|
+
set_zoning_version_development = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='ZoningHostUrl'; insert into Settings values ('ZoningHostUrl', 'https://dev-player.enplug.in/{0}/');\""
|
|
19
|
+
set_zoning_version_production = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='ZoningHostUrl'; insert into Settings values ('ZoningHostUrl', 'https://player.enplug.com/{0}/');\""
|
|
20
|
+
set_zoning_version_staging = "adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"delete from Settings where key='ZoningHostUrl'; insert into Settings values ('ZoningHostUrl', 'https://player.enplug.in/{0}/');\""
|
|
21
|
+
show_settings="adb shell sqlite3 /data/data/com.enplug.player/databases/settings.db \"select * from Settings;\""
|
|
22
|
+
uninstall_package = "adb uninstall com.enplug.player"
|
|
23
23
|
test_elevator="adb shell am broadcast -a com.enplug.player.LIFT --es Floor \"2\" --ei Arrow 1 --ei Status 0"
|
|
@@ -1,256 +1,256 @@
|
|
|
1
|
-
#!/usr/bin/python -u
|
|
2
|
-
|
|
3
|
-
import getopt
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
import shutil
|
|
7
|
-
import sys
|
|
8
|
-
import time
|
|
9
|
-
from urllib.request import Request
|
|
10
|
-
from urllib.request import urlopen
|
|
11
|
-
from urllib.request import urlretrieve
|
|
12
|
-
import subprocess
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import commands as cmd
|
|
16
|
-
|
|
17
|
-
DEVELOPMENT_DEPLOYMENTS_URL = "https://dev-devices.enplug.in/devices/app/deployments?platform=Edu"
|
|
18
|
-
PROD_DEPLOYMENTS_URL = "https://devices.enplug.com/devices/app/deployments?platform=Edu"
|
|
19
|
-
STAGING_DEPLOYMENTS_URL = "https://staging-devices.enplug.in/devices/app/deployments?platform=Edu"
|
|
20
|
-
KONE_STAGING_URL = "https://s3-us-west-2.amazonaws.com/enplug-android-image/test/StagingPlayer.apk"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def main(argv):
|
|
24
|
-
run_command(cmd.adb_devices)
|
|
25
|
-
showOptions()
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def showOptions():
|
|
29
|
-
environment = run_command(cmd.get_environment)
|
|
30
|
-
print('\nEnvironment is set to: ' + environment.upper() + '\n')
|
|
31
|
-
|
|
32
|
-
print('[1] Reboot')
|
|
33
|
-
print('[2] Clear Device Cache')
|
|
34
|
-
print('[3] Set Custom Zoning Host Version')
|
|
35
|
-
print('[4] Logs')
|
|
36
|
-
print('[5] Change Environment')
|
|
37
|
-
print('[6] Enable Web Debugger')
|
|
38
|
-
print('[7] Enable/Disable WebView')
|
|
39
|
-
print('[8] Show settings table')
|
|
40
|
-
print('[9] Test elevator')
|
|
41
|
-
print('')
|
|
42
|
-
# print ('[B] Build .exe File')
|
|
43
|
-
print('[Q] Quit')
|
|
44
|
-
sys.stdout.flush()
|
|
45
|
-
|
|
46
|
-
option = input().strip().lower()
|
|
47
|
-
|
|
48
|
-
if option == "1":
|
|
49
|
-
reboot()
|
|
50
|
-
elif option == "2":
|
|
51
|
-
clearCache()
|
|
52
|
-
elif option == "3":
|
|
53
|
-
setZoningVersion()
|
|
54
|
-
elif option == "4":
|
|
55
|
-
showLogOptions()
|
|
56
|
-
elif option == "5":
|
|
57
|
-
changeEnvironment()
|
|
58
|
-
elif option == "6":
|
|
59
|
-
enableWebDebugger()
|
|
60
|
-
elif option == "7":
|
|
61
|
-
enableDisableWebView()
|
|
62
|
-
elif option == "8":
|
|
63
|
-
showSettingsTable()
|
|
64
|
-
elif option == "9":
|
|
65
|
-
sendElevatorIntent()
|
|
66
|
-
elif option == "b":
|
|
67
|
-
build()
|
|
68
|
-
|
|
69
|
-
elif option == "q":
|
|
70
|
-
sys.exit(0)
|
|
71
|
-
|
|
72
|
-
sys.stdout.flush()
|
|
73
|
-
log('------------------------')
|
|
74
|
-
time.sleep(5)
|
|
75
|
-
showOptions()
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def build():
|
|
79
|
-
run_command(cmd.build_binary)
|
|
80
|
-
shutil.rmtree('build')
|
|
81
|
-
os.remove('commands.pyc')
|
|
82
|
-
os.remove('enplug_device.spec')
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def changeEnvironment():
|
|
86
|
-
log("Select target environment", True)
|
|
87
|
-
log('[1] Development')
|
|
88
|
-
log('[2] Staging')
|
|
89
|
-
log('[3] Production')
|
|
90
|
-
log('[4] KONE Staging')
|
|
91
|
-
option = input().strip().lower()
|
|
92
|
-
is_kone = False
|
|
93
|
-
|
|
94
|
-
if option == "1":
|
|
95
|
-
log("Changing device environment to: DEVELOPMENT", True)
|
|
96
|
-
url = DEVELOPMENT_DEPLOYMENTS_URL
|
|
97
|
-
elif option == "2":
|
|
98
|
-
log("Changing device environment to: STAGING", True)
|
|
99
|
-
url = STAGING_DEPLOYMENTS_URL
|
|
100
|
-
elif option == "3":
|
|
101
|
-
log("Changing device environment to: PRODUCTION")
|
|
102
|
-
url = PROD_DEPLOYMENTS_URL
|
|
103
|
-
elif option == "4":
|
|
104
|
-
log("Changing KONE device environment to STAGING", True)
|
|
105
|
-
is_kone = True
|
|
106
|
-
else:
|
|
107
|
-
log("Invalid input. Exiting.")
|
|
108
|
-
sys.exit()
|
|
109
|
-
|
|
110
|
-
if is_kone:
|
|
111
|
-
downloadFile(KONE_STAGING_URL, "Player.apk")
|
|
112
|
-
run_command(cmd.uninstall_package)
|
|
113
|
-
run_command(cmd.install_package)
|
|
114
|
-
log("Please wait (20s) while the script makes appropriate database changes...", True)
|
|
115
|
-
time.sleep(20)
|
|
116
|
-
run_command(cmd.change_env_to_staging)
|
|
117
|
-
run_command(cmd.reboot)
|
|
118
|
-
return
|
|
119
|
-
|
|
120
|
-
log("Fetching deployment URLs from " + url)
|
|
121
|
-
|
|
122
|
-
response = urlopen(url)
|
|
123
|
-
html = response.read()
|
|
124
|
-
package_json_data = json.loads(html)
|
|
125
|
-
player_packages = package_json_data["Result"]
|
|
126
|
-
|
|
127
|
-
for pkg in player_packages:
|
|
128
|
-
if pkg["AppName"] == "Player":
|
|
129
|
-
pkg_url = pkg["PackageUrl"]
|
|
130
|
-
log("Original URL: " + pkg_url)
|
|
131
|
-
pkg_url = pkg_url.replace('https://staging-eduapps.enplug.in', 'http://staging-eduapps.enplug.in.s3-website-us-west-2.amazonaws.com')
|
|
132
|
-
pkg_url = pkg_url.replace('https://eduapps.enplug.com', 'https://s3-us-west-2.amazonaws.com/eduapps.enplug.com')
|
|
133
|
-
pkg_url = pkg_url.replace('https://dev-eduapps.enplug.in', 'http://dev-eduapps.enplug.in.s3-website-us-west-2.amazonaws.com')
|
|
134
|
-
|
|
135
|
-
downloadFile(pkg_url, "Player.apk")
|
|
136
|
-
run_command(cmd.uninstall_package)
|
|
137
|
-
run_command(cmd.install_package)
|
|
138
|
-
if (option == "1"): # Development
|
|
139
|
-
log("Please wait (20s) while the script makes appropriate database changes (dev)...", True)
|
|
140
|
-
time.sleep(20)
|
|
141
|
-
run_command(cmd.change_env_to_development)
|
|
142
|
-
if (option == "2"): # Staging
|
|
143
|
-
log("Please wait (20s) while the script makes appropriate database changes (staging)...", True)
|
|
144
|
-
time.sleep(20)
|
|
145
|
-
run_command(cmd.change_env_to_staging)
|
|
146
|
-
if (option == "3"): # Production
|
|
147
|
-
log("Please wait (20s) while the script makes appropriate database changes (prod)...", True)
|
|
148
|
-
time.sleep(20)
|
|
149
|
-
run_command(cmd.change_env_to_production)
|
|
150
|
-
clearCache()
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
def clearCache():
|
|
154
|
-
log("Clearing cache...")
|
|
155
|
-
sys.stdout.flush()
|
|
156
|
-
run_command(cmd.clear_cache)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def downloadFile(url, filename):
|
|
160
|
-
log("Downloading package file: " + url)
|
|
161
|
-
urlretrieve(url, filename)
|
|
162
|
-
log("Downloaded file and saved as " + filename)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
def deleteAllLogFiles():
|
|
166
|
-
run_command(cmd.logs_delete_all)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
def enableDisableWebView():
|
|
170
|
-
log('[1] Enable WebView')
|
|
171
|
-
log('[2] Disable WebView')
|
|
172
|
-
option = input().strip().lower()
|
|
173
|
-
|
|
174
|
-
if option == "1":
|
|
175
|
-
log("Enabling WebView setting...", True)
|
|
176
|
-
run_command(cmd.enable_webview)
|
|
177
|
-
elif option == "2":
|
|
178
|
-
log("Disabling WebView setting...", True)
|
|
179
|
-
run_command(cmd.disable_webview)
|
|
180
|
-
else:
|
|
181
|
-
log("Invalid input. Exiting.")
|
|
182
|
-
sys.exit()
|
|
183
|
-
|
|
184
|
-
def enableWebDebugger():
|
|
185
|
-
run_command(cmd.enable_web_debugger)
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
def log(message, new_line=False):
|
|
189
|
-
if new_line:
|
|
190
|
-
print()
|
|
191
|
-
print(message)
|
|
192
|
-
sys.stdout.flush()
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
def reboot():
|
|
196
|
-
log("Rebooting device...")
|
|
197
|
-
sys.stdout.flush()
|
|
198
|
-
run_command(cmd.reboot)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
def run_command(command, *params):
|
|
202
|
-
command = command.format(*params)
|
|
203
|
-
# log("Executing command: ", True)
|
|
204
|
-
# log(' ' + command)
|
|
205
|
-
command = command.split()
|
|
206
|
-
p = subprocess.Popen(command, stdout=subprocess.PIPE)
|
|
207
|
-
out, err = p.communicate()
|
|
208
|
-
return out.strip().decode('utf-8')
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
def setZoningVersion():
|
|
212
|
-
environment = run_command(cmd.get_environment)
|
|
213
|
-
log("Enter new version: ")
|
|
214
|
-
ver = input().strip()
|
|
215
|
-
if not environment:
|
|
216
|
-
environment = run_command(cmd.get_environment)
|
|
217
|
-
|
|
218
|
-
if environment == "production":
|
|
219
|
-
run_command(cmd.set_zoning_version_production, ver)
|
|
220
|
-
elif environment == "staging":
|
|
221
|
-
run_command(cmd.set_zoning_version_staging, ver)
|
|
222
|
-
elif environment == "dev":
|
|
223
|
-
run_command(cmd.set_zoning_version_development, ver)
|
|
224
|
-
else:
|
|
225
|
-
print("Error: Unable to change version. Unknown current environment")
|
|
226
|
-
run_command(cmd.reboot)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
def showLogOptions():
|
|
230
|
-
log('[1] Download Logs Directory')
|
|
231
|
-
log('[2] Download Logs as One File')
|
|
232
|
-
log('[3] Delete All Logs')
|
|
233
|
-
option = input().strip().lower()
|
|
234
|
-
|
|
235
|
-
if option == "1":
|
|
236
|
-
log("Downloading logs directory...", True)
|
|
237
|
-
elif option == "2":
|
|
238
|
-
log("Downloading and concatenating available logs...")
|
|
239
|
-
elif option == "3":
|
|
240
|
-
log("Deleting all logs...")
|
|
241
|
-
deleteAllLogFiles()
|
|
242
|
-
else:
|
|
243
|
-
log("Invalid input. Exiting.")
|
|
244
|
-
sys.exit()
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
def showSettingsTable():
|
|
248
|
-
settingsOut = run_command(cmd.show_settings)
|
|
249
|
-
print(settingsOut)
|
|
250
|
-
|
|
251
|
-
def sendElevatorIntent():
|
|
252
|
-
elevator = run_command(cmd.test_elevator)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if __name__ == "__main__":
|
|
256
|
-
main(sys.argv[1:])
|
|
1
|
+
#!/usr/bin/python -u
|
|
2
|
+
|
|
3
|
+
import getopt
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import sys
|
|
8
|
+
import time
|
|
9
|
+
from urllib.request import Request
|
|
10
|
+
from urllib.request import urlopen
|
|
11
|
+
from urllib.request import urlretrieve
|
|
12
|
+
import subprocess
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import commands as cmd
|
|
16
|
+
|
|
17
|
+
DEVELOPMENT_DEPLOYMENTS_URL = "https://dev-devices.enplug.in/devices/app/deployments?platform=Edu"
|
|
18
|
+
PROD_DEPLOYMENTS_URL = "https://devices.enplug.com/devices/app/deployments?platform=Edu"
|
|
19
|
+
STAGING_DEPLOYMENTS_URL = "https://staging-devices.enplug.in/devices/app/deployments?platform=Edu"
|
|
20
|
+
KONE_STAGING_URL = "https://s3-us-west-2.amazonaws.com/enplug-android-image/test/StagingPlayer.apk"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main(argv):
|
|
24
|
+
run_command(cmd.adb_devices)
|
|
25
|
+
showOptions()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def showOptions():
|
|
29
|
+
environment = run_command(cmd.get_environment)
|
|
30
|
+
print('\nEnvironment is set to: ' + environment.upper() + '\n')
|
|
31
|
+
|
|
32
|
+
print('[1] Reboot')
|
|
33
|
+
print('[2] Clear Device Cache')
|
|
34
|
+
print('[3] Set Custom Zoning Host Version')
|
|
35
|
+
print('[4] Logs')
|
|
36
|
+
print('[5] Change Environment')
|
|
37
|
+
print('[6] Enable Web Debugger')
|
|
38
|
+
print('[7] Enable/Disable WebView')
|
|
39
|
+
print('[8] Show settings table')
|
|
40
|
+
print('[9] Test elevator')
|
|
41
|
+
print('')
|
|
42
|
+
# print ('[B] Build .exe File')
|
|
43
|
+
print('[Q] Quit')
|
|
44
|
+
sys.stdout.flush()
|
|
45
|
+
|
|
46
|
+
option = input().strip().lower()
|
|
47
|
+
|
|
48
|
+
if option == "1":
|
|
49
|
+
reboot()
|
|
50
|
+
elif option == "2":
|
|
51
|
+
clearCache()
|
|
52
|
+
elif option == "3":
|
|
53
|
+
setZoningVersion()
|
|
54
|
+
elif option == "4":
|
|
55
|
+
showLogOptions()
|
|
56
|
+
elif option == "5":
|
|
57
|
+
changeEnvironment()
|
|
58
|
+
elif option == "6":
|
|
59
|
+
enableWebDebugger()
|
|
60
|
+
elif option == "7":
|
|
61
|
+
enableDisableWebView()
|
|
62
|
+
elif option == "8":
|
|
63
|
+
showSettingsTable()
|
|
64
|
+
elif option == "9":
|
|
65
|
+
sendElevatorIntent()
|
|
66
|
+
elif option == "b":
|
|
67
|
+
build()
|
|
68
|
+
|
|
69
|
+
elif option == "q":
|
|
70
|
+
sys.exit(0)
|
|
71
|
+
|
|
72
|
+
sys.stdout.flush()
|
|
73
|
+
log('------------------------')
|
|
74
|
+
time.sleep(5)
|
|
75
|
+
showOptions()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def build():
|
|
79
|
+
run_command(cmd.build_binary)
|
|
80
|
+
shutil.rmtree('build')
|
|
81
|
+
os.remove('commands.pyc')
|
|
82
|
+
os.remove('enplug_device.spec')
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def changeEnvironment():
|
|
86
|
+
log("Select target environment", True)
|
|
87
|
+
log('[1] Development')
|
|
88
|
+
log('[2] Staging')
|
|
89
|
+
log('[3] Production')
|
|
90
|
+
log('[4] KONE Staging')
|
|
91
|
+
option = input().strip().lower()
|
|
92
|
+
is_kone = False
|
|
93
|
+
|
|
94
|
+
if option == "1":
|
|
95
|
+
log("Changing device environment to: DEVELOPMENT", True)
|
|
96
|
+
url = DEVELOPMENT_DEPLOYMENTS_URL
|
|
97
|
+
elif option == "2":
|
|
98
|
+
log("Changing device environment to: STAGING", True)
|
|
99
|
+
url = STAGING_DEPLOYMENTS_URL
|
|
100
|
+
elif option == "3":
|
|
101
|
+
log("Changing device environment to: PRODUCTION")
|
|
102
|
+
url = PROD_DEPLOYMENTS_URL
|
|
103
|
+
elif option == "4":
|
|
104
|
+
log("Changing KONE device environment to STAGING", True)
|
|
105
|
+
is_kone = True
|
|
106
|
+
else:
|
|
107
|
+
log("Invalid input. Exiting.")
|
|
108
|
+
sys.exit()
|
|
109
|
+
|
|
110
|
+
if is_kone:
|
|
111
|
+
downloadFile(KONE_STAGING_URL, "Player.apk")
|
|
112
|
+
run_command(cmd.uninstall_package)
|
|
113
|
+
run_command(cmd.install_package)
|
|
114
|
+
log("Please wait (20s) while the script makes appropriate database changes...", True)
|
|
115
|
+
time.sleep(20)
|
|
116
|
+
run_command(cmd.change_env_to_staging)
|
|
117
|
+
run_command(cmd.reboot)
|
|
118
|
+
return
|
|
119
|
+
|
|
120
|
+
log("Fetching deployment URLs from " + url)
|
|
121
|
+
|
|
122
|
+
response = urlopen(url)
|
|
123
|
+
html = response.read()
|
|
124
|
+
package_json_data = json.loads(html)
|
|
125
|
+
player_packages = package_json_data["Result"]
|
|
126
|
+
|
|
127
|
+
for pkg in player_packages:
|
|
128
|
+
if pkg["AppName"] == "Player":
|
|
129
|
+
pkg_url = pkg["PackageUrl"]
|
|
130
|
+
log("Original URL: " + pkg_url)
|
|
131
|
+
pkg_url = pkg_url.replace('https://staging-eduapps.enplug.in', 'http://staging-eduapps.enplug.in.s3-website-us-west-2.amazonaws.com')
|
|
132
|
+
pkg_url = pkg_url.replace('https://eduapps.enplug.com', 'https://s3-us-west-2.amazonaws.com/eduapps.enplug.com')
|
|
133
|
+
pkg_url = pkg_url.replace('https://dev-eduapps.enplug.in', 'http://dev-eduapps.enplug.in.s3-website-us-west-2.amazonaws.com')
|
|
134
|
+
|
|
135
|
+
downloadFile(pkg_url, "Player.apk")
|
|
136
|
+
run_command(cmd.uninstall_package)
|
|
137
|
+
run_command(cmd.install_package)
|
|
138
|
+
if (option == "1"): # Development
|
|
139
|
+
log("Please wait (20s) while the script makes appropriate database changes (dev)...", True)
|
|
140
|
+
time.sleep(20)
|
|
141
|
+
run_command(cmd.change_env_to_development)
|
|
142
|
+
if (option == "2"): # Staging
|
|
143
|
+
log("Please wait (20s) while the script makes appropriate database changes (staging)...", True)
|
|
144
|
+
time.sleep(20)
|
|
145
|
+
run_command(cmd.change_env_to_staging)
|
|
146
|
+
if (option == "3"): # Production
|
|
147
|
+
log("Please wait (20s) while the script makes appropriate database changes (prod)...", True)
|
|
148
|
+
time.sleep(20)
|
|
149
|
+
run_command(cmd.change_env_to_production)
|
|
150
|
+
clearCache()
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def clearCache():
|
|
154
|
+
log("Clearing cache...")
|
|
155
|
+
sys.stdout.flush()
|
|
156
|
+
run_command(cmd.clear_cache)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def downloadFile(url, filename):
|
|
160
|
+
log("Downloading package file: " + url)
|
|
161
|
+
urlretrieve(url, filename)
|
|
162
|
+
log("Downloaded file and saved as " + filename)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def deleteAllLogFiles():
|
|
166
|
+
run_command(cmd.logs_delete_all)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def enableDisableWebView():
|
|
170
|
+
log('[1] Enable WebView')
|
|
171
|
+
log('[2] Disable WebView')
|
|
172
|
+
option = input().strip().lower()
|
|
173
|
+
|
|
174
|
+
if option == "1":
|
|
175
|
+
log("Enabling WebView setting...", True)
|
|
176
|
+
run_command(cmd.enable_webview)
|
|
177
|
+
elif option == "2":
|
|
178
|
+
log("Disabling WebView setting...", True)
|
|
179
|
+
run_command(cmd.disable_webview)
|
|
180
|
+
else:
|
|
181
|
+
log("Invalid input. Exiting.")
|
|
182
|
+
sys.exit()
|
|
183
|
+
|
|
184
|
+
def enableWebDebugger():
|
|
185
|
+
run_command(cmd.enable_web_debugger)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def log(message, new_line=False):
|
|
189
|
+
if new_line:
|
|
190
|
+
print()
|
|
191
|
+
print(message)
|
|
192
|
+
sys.stdout.flush()
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def reboot():
|
|
196
|
+
log("Rebooting device...")
|
|
197
|
+
sys.stdout.flush()
|
|
198
|
+
run_command(cmd.reboot)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def run_command(command, *params):
|
|
202
|
+
command = command.format(*params)
|
|
203
|
+
# log("Executing command: ", True)
|
|
204
|
+
# log(' ' + command)
|
|
205
|
+
command = command.split()
|
|
206
|
+
p = subprocess.Popen(command, stdout=subprocess.PIPE)
|
|
207
|
+
out, err = p.communicate()
|
|
208
|
+
return out.strip().decode('utf-8')
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def setZoningVersion():
|
|
212
|
+
environment = run_command(cmd.get_environment)
|
|
213
|
+
log("Enter new version: ")
|
|
214
|
+
ver = input().strip()
|
|
215
|
+
if not environment:
|
|
216
|
+
environment = run_command(cmd.get_environment)
|
|
217
|
+
|
|
218
|
+
if environment == "production":
|
|
219
|
+
run_command(cmd.set_zoning_version_production, ver)
|
|
220
|
+
elif environment == "staging":
|
|
221
|
+
run_command(cmd.set_zoning_version_staging, ver)
|
|
222
|
+
elif environment == "dev":
|
|
223
|
+
run_command(cmd.set_zoning_version_development, ver)
|
|
224
|
+
else:
|
|
225
|
+
print("Error: Unable to change version. Unknown current environment")
|
|
226
|
+
run_command(cmd.reboot)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def showLogOptions():
|
|
230
|
+
log('[1] Download Logs Directory')
|
|
231
|
+
log('[2] Download Logs as One File')
|
|
232
|
+
log('[3] Delete All Logs')
|
|
233
|
+
option = input().strip().lower()
|
|
234
|
+
|
|
235
|
+
if option == "1":
|
|
236
|
+
log("Downloading logs directory...", True)
|
|
237
|
+
elif option == "2":
|
|
238
|
+
log("Downloading and concatenating available logs...")
|
|
239
|
+
elif option == "3":
|
|
240
|
+
log("Deleting all logs...")
|
|
241
|
+
deleteAllLogFiles()
|
|
242
|
+
else:
|
|
243
|
+
log("Invalid input. Exiting.")
|
|
244
|
+
sys.exit()
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def showSettingsTable():
|
|
248
|
+
settingsOut = run_command(cmd.show_settings)
|
|
249
|
+
print(settingsOut)
|
|
250
|
+
|
|
251
|
+
def sendElevatorIntent():
|
|
252
|
+
elevator = run_command(cmd.test_elevator)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
if __name__ == "__main__":
|
|
256
|
+
main(sys.argv[1:])
|