blob: 86ac512dfa1b659e228be371f792a7aedfeb94cc [file] [log] [blame]
agsantos1e7736c2020-10-28 14:39:13 -04001#!/usr/bin/env python3
2#
Sébastien Blincb783e32021-02-12 11:34:10 -05003# Copyright (C) 2020-2021 Savoir-faire Linux Inc.
agsantos1e7736c2020-10-28 14:39:13 -04004#
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
24import os
25import json
26from termcolor import colored, cprint
27
28from sdkConstants import *
29from pluginStructureProfile import PluginStructure
30
31
32class Manifest(PluginStructure):
33 def __init__(self, action):
34 PluginStructure.__init__(self, action)
35 self.description = ''
36 self.version = '0'
37 self.manifest = {}
38 with open("./Templates/manifest.json") as f:
39 self.manifestSkeleton = f.read()
40 f.close()
41 if (self.isManifest()):
42 with open(self.manifestFile) as f:
43 self.manifest = json.load(f)
44 f.close()
45 self.pluginName = self.manifest["name"]
46 self.description = self.manifest["description"]
47 self.version = self.manifest["version"]
48
49 def checkVersionFormat(self, version):
50 return False if (len(version.split('.')) != 3) else True
51
52 def createManifest(self):
53 print(
54 f"\nDefining a manifest for \"{self.pluginName}\" plugin, we gonna need more information..")
55 print(colored("\nPress 'q' to quit this option.", "yellow"))
56
57 pluginDescription = input("\nTell us a description: ")
58 if (pluginDescription == 'q'):
59 return False
60 self.description = pluginDescription
61 pluginVersion = '0'
62 while (not self.checkVersionFormat(
63 pluginVersion) and pluginVersion != ""):
64 print(colored("\nVersion must be of the form X.Y.Z", "yellow"))
65 pluginVersion = input("Set plugin version (default 0.0.0): ")
66 if (pluginVersion == 'q'):
67 return False
68 if (not pluginVersion):
69 pluginVersion = '0.0.0'
70 self.version = pluginVersion
71 self.manifest["name"] = self.pluginName
72 self.manifest["description"] = self.description
73 self.manifest["version"] = self.version
74
75 self.saveManifest(self.manifest)
76 return True
77
78 def modifyManifestInternal(self, action):
79 self.callUpdateVersion = False
80 if (action == ACTIONS["DELETE_MANIFEST"]):
81 self.deleteManifest()
82 elif (self.isManifest()):
83 self.manifest["name"] = self.pluginName
84 pluginDescription = input(
85 "New description for your plugin (ignore to keep previous description): ")
86 pluginVersion = input(
87 "New plugin version (ignore to keep previous version): ")
88 while (not self.checkVersionFormat(
89 pluginVersion) and pluginVersion != ""):
90 print("Version must be of the form X.Y.Z")
91 pluginVersion = input(
92 "New plugin version (ignore to keep previous version): ")
93 if (pluginDescription != ""):
94 self.description = pluginDescription
95 self.manifest["description"] = self.description
96 if (pluginVersion !=
97 "" and self.manifest["version"] != pluginVersion):
98 self.version = pluginVersion
99 self.manifest["version"] = self.version
100 self.callUpdateVersion = True
101 self.saveManifest(self.manifest)
102 else:
103 self.createManifest()
104 return self.callUpdateVersion