agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2020 Savoir-faire Linux Inc. |
| 4 | # |
| 5 | # Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation, either version 3 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # |
| 20 | # Creates packaging targets for a distribution and architecture. |
| 21 | # This helps reduce the length of the top Makefile. |
| 22 | # |
| 23 | |
| 24 | import os |
| 25 | import sys |
| 26 | import json |
| 27 | from zipfile import ZipFile |
| 28 | from termcolor import colored, cprint |
| 29 | |
| 30 | from sdkConstants import * |
| 31 | from preferencesProfile import Preferences |
| 32 | |
| 33 | |
| 34 | class SkeletonSourceFiles(Preferences): |
| 35 | def __init__(self, action): |
| 36 | Preferences.__init__(self, action) |
| 37 | self.names = [] |
| 38 | self.apis = [] |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 39 | self.dataTypes = [] |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 40 | self.mainFile = self.pluginDirectory + "/main.cpp" |
| 41 | self.newNames = [] |
| 42 | self.globNames() |
| 43 | self.initPackage() |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 44 | with open('./Templates/defaultStrings.json') as f: |
| 45 | self.defaultStrings = json.load(f) |
| 46 | f.close() |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 47 | |
| 48 | def initPackage(self): |
| 49 | if os.path.exists(self.packageFile): |
| 50 | with open(self.packageFile, 'r') as f: |
| 51 | self.package = json.load(f) |
| 52 | |
| 53 | def updateMainFileVersion(self): |
| 54 | if os.path.exists(self.mainFile): |
| 55 | with open(self.mainFile, 'r') as f: |
| 56 | lines = f.readlines() |
| 57 | splits = self.version.split('.') |
| 58 | if (not self.version): |
| 59 | splits = ['', '', ''] |
| 60 | splitStr = [ |
| 61 | "#define " + |
| 62 | self.pluginName + |
| 63 | "_VERSION_MAJOR ", |
| 64 | "#define " + |
| 65 | self.pluginName + |
| 66 | "_VERSION_MINOR ", |
| 67 | "#define " + |
| 68 | self.pluginName + |
| 69 | "_VERSION_PATCH "] |
| 70 | outStr = [] |
| 71 | idx = 0 |
| 72 | for line in lines: |
| 73 | if (idx < 3 and splitStr[idx] in line): |
| 74 | parts = line.split(splitStr[idx]) |
| 75 | line = line.replace(parts[-1], splits[idx] + "\n") |
| 76 | idx += 1 |
| 77 | outStr.append(line) |
| 78 | f.close() |
| 79 | with open(self.mainFile, 'w') as f: |
| 80 | f.write(''.join(outStr)) |
| 81 | |
| 82 | def updatePackageFileVersion(self): |
| 83 | if os.path.exists(self.packageFile): |
| 84 | if(not self.package): |
| 85 | with open(self.packageFile, 'w') as f: |
| 86 | self.package = json.load(f) |
| 87 | f.close() |
| 88 | self.package["version"] = self.version |
| 89 | with open(self.packageFile, 'w') as f: |
| 90 | json.dump(self.package, f, indent=4) |
| 91 | f.close() |
| 92 | |
| 93 | def updateCMakeListsFileVersion(self): |
| 94 | if os.path.exists(self.cmakelistsFile): |
| 95 | with open(self.cmakelistsFile, 'r') as f: |
| 96 | outStr = f.read() |
| 97 | lines = outStr.split("\n") |
| 98 | for i, line in enumerate(lines): |
| 99 | if ("set (Version " in line): |
| 100 | lines[i] = f"set (Version {self.version})" |
| 101 | break |
| 102 | f.close() |
| 103 | |
| 104 | with open(self.cmakelistsFile, 'w') as f: |
| 105 | f.write('\n'.join(lines)) |
| 106 | f.close() |
| 107 | |
| 108 | def updateVersion(self): |
| 109 | self.updateMainFileVersion() |
| 110 | self.updatePackageFileVersion() |
| 111 | self.updateCMakeListsFileVersion() |
| 112 | |
| 113 | def createMain(self, addAllowed='y'): |
| 114 | if (not self.isManifest()): |
| 115 | self.createManifest() |
| 116 | with open('./Templates/main.cpp') as f: |
| 117 | mainStr = f.read() |
| 118 | mainStr = mainStr.replace('HEADER', self.header) |
| 119 | mainStr = mainStr.replace('PLUGINNAME', self.pluginName) |
| 120 | if (not self.checkVersionFormat(self.version)): |
| 121 | self.version = '0.0.0' |
| 122 | version = self.version.split(".") |
| 123 | pluginVersionMajor = version[0] |
| 124 | pluginVersionMinor = version[1] |
| 125 | pluginVersionPatch = version[2] |
| 126 | |
| 127 | mainStr = mainStr.replace('PLUGINVERSIONMAJOR', pluginVersionMajor) |
| 128 | mainStr = mainStr.replace('PLUGINVERSIONMINOR', pluginVersionMinor) |
| 129 | mainStr = mainStr.replace('PLUGINVERSIONPATCH', pluginVersionPatch) |
| 130 | splits = mainStr.split("----------------") |
| 131 | includesAPIStr = None |
| 132 | pluginAPIStr = None |
| 133 | for i, split in enumerate(splits): |
| 134 | if ("PLUGINAPI" in split and "APIMANAGER" in split): |
| 135 | if (not pluginAPIStr): |
| 136 | pluginAPIStr = self.createHandlers(split) |
| 137 | splits[i] = splits[i].replace(split, pluginAPIStr) |
| 138 | if ("INCLUDESAPI" in split): # must always be called first |
| 139 | if (not includesAPIStr): |
| 140 | includesAPIStr = self.getIncludeStr(split, addAllowed) |
| 141 | splits[i] = splits[i].replace(split, includesAPIStr) |
| 142 | |
| 143 | mainStr = ''.join(splits) |
| 144 | f.close() |
| 145 | with open(self.mainFile, 'w') as f: |
| 146 | f.write(mainStr) |
| 147 | f.close() |
| 148 | return True |
| 149 | |
| 150 | def globNames(self): |
| 151 | if (self.isMainDirectory()): |
| 152 | files = os.listdir(self.pluginDirectory) |
| 153 | for file in files: |
| 154 | if (".h" in file): |
| 155 | if (("MediaHandler" in file or "ConversationHandler" in file)): |
| 156 | name = file.replace(".h", "") |
| 157 | name = name.replace("MediaHandler", "") |
| 158 | name = name.replace("ConversationHandler", "") |
| 159 | self.names.append(name) |
| 160 | if ("MediaHandler" in file): |
| 161 | self.apis.append(PLUGINS_APIS["MEDIA_HANDLER"]) |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 162 | elif ("ConversationHandler" in file): |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 163 | self.apis.append(PLUGINS_APIS["CONVERSATION_HANDLER"]) |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 164 | if ("Subscriber" in file): |
| 165 | if ("Video" in file): |
| 166 | self.dataTypes.append(DATA_TYPES["VIDEO"]) |
| 167 | elif ("Audio" in file): |
| 168 | self.dataTypes.append(DATA_TYPES["AUDIO"]) |
| 169 | elif ("Conversation" in file): |
| 170 | self.dataTypes.append(DATA_TYPES["TEXT"]) |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 171 | |
| 172 | def createHandlers(self, split): |
| 173 | if (len(self.names) == 0): |
| 174 | return "" |
| 175 | createStr = "" |
| 176 | for i, name in enumerate(self.names): |
| 177 | if (self.apis[i] == PLUGINS_APIS["MEDIA_HANDLER"]): |
| 178 | temp = split.replace("PLUGINAPI", f"{name}MediaHandler") |
| 179 | temp = temp.replace("APIMANAGER", "CallMediaHandlerManager") |
| 180 | elif (self.apis[i] == PLUGINS_APIS["CONVERSATION_HANDLER"]): |
| 181 | temp = split.replace("PLUGINAPI", f"{name}ConversationHandler") |
| 182 | temp = temp.replace("APIMANAGER", "ConversationHandlerManager") |
| 183 | createStr += temp |
| 184 | return createStr |
| 185 | |
| 186 | def getIncludeStr(self, split='', addAllowed='y'): |
| 187 | includesStr = "" |
| 188 | self.newNames = [] |
| 189 | while (addAllowed == "y" or addAllowed == "Y"): |
| 190 | addAllowed = '' |
| 191 | functionName = "" |
| 192 | while(functionName == "" or functionName in self.names): |
| 193 | functionName = input("\nChose a functionality name: ") |
| 194 | functionName = pattern.sub('', functionName) |
| 195 | apiType = '' |
| 196 | while (apiType not in PLUGINS_APIS.values()): |
| 197 | print(f"\nChoose a API for functionality \"{functionName}\".") |
| 198 | print("\nAvailable APIs: ") |
| 199 | print("(1) video during a call (Media Handler API)") |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 200 | print("(2) audio during a call (Media Handler API)") |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 201 | print( |
| 202 | colored( |
| 203 | "For more information about the API, call help preferences.", |
| 204 | "yellow")) |
| 205 | # or (2) to chat messages: ") |
| 206 | apiType = input("\nEnter a data type number: ") |
| 207 | if (apiType not in PLUGINS_APIS.values()): |
| 208 | print(colored(f"Data type '{apiType}' not valid!", "red")) |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 209 | else: |
| 210 | self.dataTypes.append(list(DATA_TYPES.values())[int(apiType)-1]) |
| 211 | if (apiType == PLUGINS_APIS["MEDIA_HANDLER_AUDIO"]): |
| 212 | apiType = PLUGINS_APIS["MEDIA_HANDLER"] |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 213 | self.names.append(functionName) |
| 214 | self.newNames.append(functionName) |
| 215 | self.apis.append(apiType) |
| 216 | while (addAllowed not in ['y', 'N', 'Y', 'n']): |
| 217 | addAllowed = input("\nAdd another functionaliy? [y/N] ") |
| 218 | if not addAllowed: |
| 219 | addAllowed = 'N' |
| 220 | break |
| 221 | for j, item in enumerate(self.apis): |
| 222 | temp = '' |
| 223 | localNames = self.names.copy() |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 224 | if (item == PLUGINS_APIS["MEDIA_HANDLER"]): |
| 225 | localNames[j] = self.names[j] + "MediaHandler" |
| 226 | if (split): |
| 227 | temp = split.replace("INCLUDESAPI", localNames[j]) |
| 228 | elif (item == PLUGINS_APIS["CONVERSATION_HANDLER"]): |
| 229 | localNames[j] = self.names[j] + "ConversationHandler" |
| 230 | if (split): |
| 231 | temp = split.replace("INCLUDESAPI", localNames[j]) |
| 232 | includesStr += temp |
| 233 | if (self.newNames != []): |
| 234 | self.createAPIHeaderFiles() |
| 235 | self.createAPIImplFiles() |
| 236 | return includesStr |
| 237 | |
| 238 | def createAPIHeaderFiles(self): |
| 239 | for j, item in enumerate(self.apis): |
| 240 | if (self.names[j] in self.newNames): |
| 241 | if (item == PLUGINS_APIS["MEDIA_HANDLER"]): |
| 242 | with open('./Templates/genericMediaHandler.h', 'r') as f: |
| 243 | data = f.read() |
| 244 | data = data.replace("HEADER", self.header) |
| 245 | data = data.replace("GENERIC", self.names[j]) |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 246 | data = data.replace("DATATYPE", self.dataTypes[j]) |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 247 | f.close() |
| 248 | with open(f"{self.pluginDirectory}/{self.names[j]}MediaHandler.h", 'w') as f: |
| 249 | f.write(data) |
| 250 | f.close() |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 251 | with open('./Templates/genericMediaSubscriber.h', 'r') as f: |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 252 | data = f.read() |
| 253 | data = data.replace("HEADER", self.header) |
| 254 | data = data.replace("GENERIC", self.names[j]) |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 255 | data = data.replace("DATATYPE", self.dataTypes[j]) |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 256 | f.close() |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 257 | data = data.split("---") |
| 258 | for k, dataItem in enumerate(data): |
| 259 | if (f"{self.dataTypes[j]}INCLUDES" in dataItem): |
| 260 | tempString = data[k] |
| 261 | data[k] = "" |
| 262 | if (self.defaultStrings["genericmediasubscriber"]["header"][f"{self.dataTypes[j]}INCLUDES"]): |
| 263 | for string in self.defaultStrings["genericmediasubscriber"]["header"][f"{self.dataTypes[j]}INCLUDES"]: |
| 264 | data[k] += tempString.replace(f"{self.dataTypes[j]}INCLUDES", string) |
| 265 | elif (f"{self.dataTypes[j]}PRIVATE" in dataItem): |
| 266 | tempString = data[k] |
| 267 | data[k] = "" |
| 268 | if (self.defaultStrings["genericmediasubscriber"]["header"][f"{self.dataTypes[j]}PRIVATE"]): |
| 269 | for string in self.defaultStrings["genericmediasubscriber"]["header"][f"{self.dataTypes[j]}PRIVATE"]: |
| 270 | data[k] += tempString.replace(f"{self.dataTypes[j]}PRIVATE", string) |
| 271 | data = "".join(data) |
| 272 | with open(f"{self.pluginDirectory}/{self.names[j]}{self.dataTypes[j]}Subscriber.h", 'w') as f: |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 273 | f.write(data) |
| 274 | f.close() |
| 275 | elif (item == PLUGINS_APIS["CONVERSATION_HANDLER"]): |
| 276 | with open('./Templates/genericConversationHandler.h', 'r') as f: |
| 277 | data = f.read() |
| 278 | data = data.replace("HEADER", self.header) |
| 279 | data = data.replace('GENERIC', self.names[j]) |
| 280 | f.close() |
| 281 | with open(f"{self.pluginDirectory}/{self.names[j]}ConversationHandler.h", 'w') as f: |
| 282 | f.write(data) |
| 283 | f.close() |
| 284 | |
| 285 | def createAPIImplFiles(self): |
| 286 | for j, item in enumerate(self.apis): |
| 287 | if (self.names[j] in self.newNames): |
| 288 | if (item == PLUGINS_APIS["MEDIA_HANDLER"]): |
| 289 | with open('./Templates/genericMediaHandler.cpp', 'r') as f: |
| 290 | data = f.read() |
| 291 | data = data.replace("HEADER", self.header) |
| 292 | data = data.replace("PLUGINNAME", self.pluginName) |
| 293 | data = data.replace("GENERIC", self.names[j]) |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 294 | data = data.replace("DATATYPE", self.dataTypes[j]) |
| 295 | data = data.replace("DataType", self.dataTypes[j].lower()) |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 296 | f.close() |
| 297 | with open(f"{self.pluginDirectory}/{self.names[j]}MediaHandler.cpp", 'w') as f: |
| 298 | f.write(data) |
| 299 | f.close() |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 300 | with open('./Templates/genericMediaSubscriber.cpp', 'r') as f: |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 301 | data = f.read() |
| 302 | data = data.replace("HEADER", self.header) |
| 303 | data = data.replace("GENERIC", self.names[j]) |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 304 | data = data.replace("DATATYPE", self.dataTypes[j]) |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 305 | f.close() |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 306 | data = data.split("---") |
| 307 | for k, dataItem in enumerate(data): |
| 308 | if (f"FFMPEG{self.dataTypes[j]}INCLUDES" in dataItem): |
| 309 | tempString = data[k] |
| 310 | tempStringSplits = tempString.split("\n")[1:] |
| 311 | data[k] = "" |
| 312 | if (self.defaultStrings["genericmediasubscriber"]["impl"][f"FFMPEG{self.dataTypes[j]}INCLUDES"]): |
| 313 | for string in self.defaultStrings["genericmediasubscriber"]["impl"][f"FFMPEG{self.dataTypes[j]}INCLUDES"]: |
| 314 | data[k] += tempStringSplits[1].replace(f"FFMPEG{self.dataTypes[j]}INCLUDES", string) + "\n" |
| 315 | tempStringSplits[1] = data[k] |
| 316 | data[k] = tempStringSplits[0] + "\n" + tempStringSplits[1] + tempStringSplits[2] |
| 317 | elif (f"{self.dataTypes[j]}INCLUDES" in dataItem): |
| 318 | tempString = data[k] |
| 319 | data[k] = "" |
| 320 | if (self.defaultStrings["genericmediasubscriber"]["impl"][f"{self.dataTypes[j]}INCLUDES"]): |
| 321 | for string in self.defaultStrings["genericmediasubscriber"]["impl"][f"{self.dataTypes[j]}INCLUDES"]: |
| 322 | data[k] += tempString.replace(f"{self.dataTypes[j]}INCLUDES", string) |
| 323 | elif (f"{self.dataTypes[j]}UPDATE" in dataItem): |
| 324 | fileName = self.defaultStrings["genericmediasubscriber"]["impl"][f"{self.dataTypes[j]}UPDATE"] |
| 325 | with open(f"./Templates/{fileName}") as updateFile: |
| 326 | updateTxt = updateFile.read() |
| 327 | updateFile.close() |
| 328 | data[k] = data[k].replace(f"{self.dataTypes[j]}UPDATE", updateTxt) |
| 329 | |
| 330 | data = "".join(data) |
| 331 | with open(f"{self.pluginDirectory}/{self.names[j]}{self.dataTypes[j]}Subscriber.cpp", 'w') as f: |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 332 | f.write(data) |
| 333 | f.close() |
| 334 | elif (item == PLUGINS_APIS["CONVERSATION_HANDLER"]): |
| 335 | with open('./Templates/genericConversationHandler.cpp', 'r') as f: |
| 336 | data = f.read() |
| 337 | data = data.replace("HEADER", self.header) |
| 338 | data = data.replace("GENERIC", self.names[j]) |
| 339 | f.close() |
| 340 | with open(f"{self.pluginDirectory}/{self.names[j]}ConversationHandler.cpp", 'w') as f: |
| 341 | f.write(data) |
| 342 | f.close() |
| 343 | self.createPreferences(self.names) |
| 344 | self.setRuntimePreferences() |
| 345 | |
| 346 | def setRuntimePreferences(self): |
| 347 | for j, item in enumerate(self.apis): |
| 348 | baseStr1 = '' |
| 349 | baseStr2 = '' |
| 350 | if (len(self.newNames) > 0 and self.names[j] in self.newNames): |
| 351 | if (item == PLUGINS_APIS["MEDIA_HANDLER"]): |
| 352 | with open(f"{self.pluginDirectory}/{self.names[j]}MediaHandler.cpp", 'r') as f: |
| 353 | data = f.read() |
| 354 | parts = data.split("----------------") |
| 355 | for part in parts: |
| 356 | if "PREFERENCE1" in part: |
| 357 | baseStr1 = part |
| 358 | if "PREFERENCE2" in part: |
| 359 | baseStr2 = part |
| 360 | newStr1 = '' |
| 361 | newStr2 = '' |
| 362 | for preference in self.preferences: |
| 363 | if (self.names[j] in preference['scope']): |
| 364 | editable = '' |
| 365 | while(editable not in ['y', 'n']): |
| 366 | editable = input( |
| 367 | f"\nThe preference {preference['title']} will be changeable during running time\nfor {self.names[j]} functionality? [y/n] ") |
| 368 | if (editable == 'y'): |
| 369 | newStr1 += baseStr1.replace( |
| 370 | "PREFERENCE1", preference['key']) |
| 371 | newStr2 += baseStr2.replace( |
| 372 | "PREFERENCE2", preference['key']) |
| 373 | data = data.replace(baseStr1, newStr1) |
| 374 | data = data.replace(baseStr2, newStr2) |
| 375 | f.close() |
| 376 | with open(f"{self.pluginDirectory}/{self.names[j]}MediaHandler.cpp", 'w') as f: |
| 377 | parts = data.split("----------------") |
| 378 | f.write(''.join(parts)) |
| 379 | f.close() |
| 380 | elif (item == PLUGINS_APIS["CONVERSATION_HANDLER"]): |
| 381 | with open(f"{self.pluginDirectory}/{self.names[j]}ConversationHandler.cpp", 'r') as f: |
| 382 | data = f.read() |
| 383 | parts = data.split("----------------") |
| 384 | for part in parts: |
| 385 | if "PREFERENCE1" in part: |
| 386 | baseStr1 = part |
| 387 | if "PREFERENCE2" in part: |
| 388 | baseStr2 = part |
| 389 | newStr1 = '' |
| 390 | newStr2 = '' |
| 391 | for preference in self.preferences: |
| 392 | if (self.names[j] in preference['scope']): |
| 393 | editable = '' |
| 394 | while(editable not in ['y', 'n']): |
| 395 | editable = input( |
| 396 | f"\nThe preference {preference['title']} will be changeable during running time\nfor {self.names[j]} functionality? [y/n] ") |
| 397 | if (editable == 'y'): |
| 398 | newStr1 += baseStr1.replace( |
| 399 | "PREFERENCE1", preference['key']) |
| 400 | newStr2 += baseStr2.replace( |
| 401 | "PREFERENCE1", preference['key']) |
| 402 | data = data.replace(baseStr1, newStr1) |
| 403 | data = data.replace(baseStr2, newStr2) |
| 404 | f.close() |
| 405 | with open(f"{self.pluginDirectory}/{self.names[j]}ConversationHandler.cpp", 'w') as f: |
| 406 | parts = data.split("----------------") |
| 407 | f.write(''.join(parts)) |
| 408 | f.close() |
| 409 | |
| 410 | def createFunctionality(self): |
| 411 | if (not self.isManifest()): |
| 412 | print("\nBefore creating a functionality, you must define your manifest.") |
| 413 | self.createManifest() |
| 414 | print("\nManifest ok, continuing functionality creation.") |
| 415 | self.getIncludeStr() |
| 416 | self.createMain(addAllowed='n') |
| 417 | self.createBuildFiles() |
| 418 | |
| 419 | def modifyManifest(self, action): |
| 420 | if (self.modifyManifestInternal(action)): |
| 421 | self.updateVersion() |
| 422 | |
| 423 | def createPackageJson(self): |
| 424 | if (not self.isManifest()): |
| 425 | print("\nBefore creating a package, you must define your manifest.") |
| 426 | self.createManifest() |
| 427 | print("\nManifest ok, continuing package creation.") |
| 428 | with open("./Templates/package.json") as f: |
| 429 | self.package = json.load(f) |
| 430 | self.package["name"] = self.pluginName |
| 431 | self.package["version"] = self.version |
| 432 | if (not self.checkVersionFormat(self.version)): |
| 433 | self.package["version"] = '0.0.0' |
| 434 | f.close() |
| 435 | |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 436 | for api in self.apis: |
| 437 | if api == PLUGINS_APIS["MEDIA_HANDLER"]: |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 438 | for dep in self.defaultStrings["package.json"]["MediaHandler"]["deps"]: |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 439 | if dep not in self.package["deps"]: |
| 440 | self.package["deps"].append(dep) |
| 441 | with open(f"{self.pluginDirectory}/package.json", 'w') as f: |
| 442 | json.dump(self.package, f, indent=4) |
| 443 | f.close() |
| 444 | |
| 445 | print("\nPackage ok.") |
| 446 | |
| 447 | def globFiles(self, baseStr, key, ext): |
| 448 | import glob |
| 449 | files = glob.glob(f"{self.pluginDirectory}/**.{ext}", recursive=True) |
| 450 | outputStr = "" |
| 451 | for item in files: |
| 452 | name = os.path.split(item)[1] |
| 453 | outputStr += baseStr.replace(key, name) |
| 454 | return outputStr |
| 455 | |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 456 | def fillBuildFile(self, inputStr, fileType): #fileType = 0 -> build.sh; fileType = 1 -> CMakeLists.txt |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 457 | inputStr = inputStr.replace('PLUGINNAME', self.pluginName) |
| 458 | inputStr = inputStr.replace('MANIFESTVERSION', self.version) |
| 459 | splits = inputStr.split('---') |
| 460 | tempPart = [] |
| 461 | for i, split in enumerate(splits): |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 462 | if ("FFMPEG" in split |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 463 | and PLUGINS_APIS['MEDIA_HANDLER'] not in self.apis): |
| 464 | splits[i] = '' |
| 465 | elif ("CPPFILENAME" in split): |
| 466 | splits[i] = self.globFiles(split, "CPPFILENAME", "cpp") |
| 467 | elif ("HFILENAME" in split): |
| 468 | splits[i] = self.globFiles(split, "HFILENAME", "h") |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 469 | elif ("FFMPEGEXTRA" in split): |
| 470 | splits[i] = splits[i].replace("FFMPEGEXTRA", "") |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 471 | elif ("FFMPEGCPP" in split): |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 472 | tempString = splits[i] |
| 473 | splits[i] = "" |
| 474 | for item in self.defaultStrings["buildFiles"]["MediaHandler"][f"{self.ffmpegBuildOption}FFMPEGCPP"]: |
| 475 | splits[i] += tempString.replace("FFMPEGCPP", item) |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 476 | elif ("FFMPEGH" in split): |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 477 | tempString = splits[i] |
| 478 | splits[i] = "" |
| 479 | for item in self.defaultStrings["buildFiles"]["MediaHandler"][f"{self.ffmpegBuildOption}FFMPEGH"]: |
| 480 | splits[i] += tempString.replace("FFMPEGH", item) |
| 481 | elif ("FFMPEGLIBS" in split): |
| 482 | tempString = splits[i] |
| 483 | splits[i] = "" |
| 484 | for item in self.defaultStrings["buildFiles"]["MediaHandler"][f"{self.ffmpegBuildOption}FFMPEGLIBS"]: |
| 485 | if (fileType): |
| 486 | splits[i] += tempString.replace("FFMPEGLIBS", f"{item} ") |
| 487 | else: |
| 488 | splits[i] += tempString.replace("FFMPEGLIBS", f"-l:lib{item}.a") |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 489 | inputStr = ''.join(splits) |
| 490 | return inputStr |
| 491 | |
| 492 | def createBuildFiles(self): |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 493 | self.ffmpegBuildOption = None |
| 494 | for typeItem in self.dataTypes: |
| 495 | if (typeItem == DATA_TYPES["VIDEO"]): |
| 496 | self.ffmpegBuildOption = 'Video' |
| 497 | break |
| 498 | elif (typeItem == DATA_TYPES["AUDIO"]): |
| 499 | self.ffmpegBuildOption = 'Audio' |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 500 | with open("./Templates/CMakeLists.txt", 'r') as f: |
| 501 | cmakelists = f.read() |
| 502 | f.close() |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 503 | cmakelists = self.fillBuildFile(cmakelists, 1) |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 504 | with open(self.cmakelistsFile, 'w') as f: |
| 505 | f.write(cmakelists) |
| 506 | f.close() |
| 507 | |
| 508 | with open("./Templates/build.sh", 'r') as f: |
| 509 | build = f.read() |
| 510 | f.close() |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame^] | 511 | build = self.fillBuildFile(build, 0) |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 512 | with open(self.buildFile, 'w') as f: |
| 513 | f.write(build) |
| 514 | f.close() |
| 515 | |
| 516 | print("\nCMakeLists.txt and build.sh ok.") |
| 517 | return |