Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
122 lines (109 loc) · 3.82 KB
/
Copy pathutils.js
File metadata and controls
122 lines (109 loc) · 3.82 KB
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
const FILE_TYPE_FILE = 0;
const FILE_TYPE_DIRECTORY = 1;
var utils;
if (isNode()) {
utils = require('./utils-node.js');
} else {
utils = require('./utils-xpc.js');
}
function isNode() {
try {
return process && process.versions && process.versions.node;
} catch (e) {
return false;
}
}
function isSubjectToBranding(path) {
return /shared[\/\\][a-zA-Z]+[\/\\]branding$/.test(path) ||
/branding[\/\\]initlogo.png/.test(path);
}
function getExtension(filename) {
return filename.substr(filename.lastIndexOf('.') + 1).toLowerCase();
}
// We parse list like ps aux and b2g-ps into object
function psParser(out) {
var rows = out.split('\n');
if (rows.length < 2)
return {};
// We use indexes of each title of the first row to
// get correct position of each values.
// We don't use split(' ') here, because some app name
// may contain white space, ex. FM Radio.
var titles = rows[0].trim().split(/\s+/);
var titleIndexes = titles.map(function(name) {
return rows[0].indexOf(name);
});
var result = {};
for (var r = 1; r < rows.length; r++) {
var name =
rows[r].slice(titleIndexes[0], titleIndexes[1]).
trim();
result[name] = {};
for (var i = 1; i < titleIndexes.length; i++) {
var value =
rows[r].slice(titleIndexes[i], titleIndexes[i + 1]);
if(value[0] !== ' ') {
value = rows[r].slice(titleIndexes[i] - 1,
titleIndexes[i + 1] && titleIndexes[i + 1] - 1);
}
value = value.trim();
result[name][titles[i]] = value;
}
}
return result;
}
function gaiaOriginURL(name, scheme, domain, port) {
return scheme + name + '.' + domain + (port ? port : '');
}
function gaiaManifestURL(name, scheme, domain, port) {
return gaiaOriginURL(name, scheme, domain, port) + '/manifest.webapp';
}
exports.Q = utils.Q;
exports.isSubjectToBranding = isSubjectToBranding;
exports.ls = utils.ls;
exports.getFileContent = utils.getFileContent;
exports.writeContent = utils.writeContent;
exports.getFile = utils.getFile;
exports.ensureFolderExists = utils.ensureFolderExists;
exports.getJSON = utils.getJSON;
exports.getFileAsDataURI = utils.getFileAsDataURI;
exports.makeWebappsObject = utils.makeWebappsObject;
exports.gaiaOriginURL = gaiaOriginURL;
exports.gaiaManifestURL = gaiaManifestURL;
exports.getDistributionFileContent = utils.getDistributionFileContent;
exports.resolve = utils.resolve;
exports.getGaia = utils.getGaia;
exports.getBuildConfig = utils.getBuildConfig;
exports.getAppsByList = utils.getAppsByList;
exports.getApp = utils.getApp;
exports.getAppName = utils.getAppName;
exports.getXML = utils.getXML;
exports.getTempFolder = utils.getTempFolder;
exports.normalizeString = utils.normalizeString;
exports.Commander = utils.Commander;
exports.getEnvPath = utils.getEnvPath;
exports.getLocaleBasedir = utils.getLocaleBasedir;
// ===== the following functions support node.js compitable interface.
exports.FILE_TYPE_FILE = FILE_TYPE_FILE;
exports.FILE_TYPE_DIRECTORY = FILE_TYPE_DIRECTORY;
exports.deleteFile = utils.deleteFile;
exports.listFiles = utils.listFiles;
exports.psParser = psParser;
exports.fileExists = utils.fileExists;
exports.mkdirs = utils.mkdirs;
exports.joinPath = utils.joinPath;
exports.copyFileTo = utils.copyFileTo;
exports.createXMLHttpRequest = utils.createXMLHttpRequest;
exports.downloadJSON = utils.downloadJSON;
exports.readJSONFromPath = utils.readJSONFromPath;
exports.readZipManifest = utils.readZipManifest;
exports.writeContentToFile = utils.writeContentToFile;
exports.processEvents = utils.processEvents;
exports.log = utils.log;
exports.getExtension = getExtension;
exports.killAppByPid = utils.killAppByPid;
exports.getEnv = utils.getEnv;
exports.isExternalApp = utils.isExternalApp;
exports.getDocument = utils.getDocument;
exports.getWebapp = utils.getWebapp;
exports.Services = utils.Services;