@@ -80,14 +80,14 @@ def getInterfaceName(self):
80
80
81
81
def getAvaiable (self ):
82
82
return self .available
83
-
83
+
84
84
def getIcon (self ):
85
85
return self .icon
86
86
87
87
class MusicPackageManager :
88
88
_instance = None
89
89
packages = None
90
-
90
+
91
91
@classmethod
92
92
def get_instance (cls ):
93
93
if cls ._instance is None :
@@ -100,7 +100,7 @@ def __init__(self):
100
100
with open ('./sounds/notes/music_package.json' ) as json_file :
101
101
data = json .load (json_file )
102
102
for p in data ['packages' ]:
103
-
103
+
104
104
package = data ['packages' ][p ]
105
105
mp = MusicPackage (p ,package ['category' ],package ['name_IT' ],package ['name_EN' ],package ['version' ],package ['date' ])
106
106
for i in package ['interface' ]:
@@ -115,18 +115,21 @@ def __init__(self):
115
115
116
116
def deletePackage (self , packageName ):
117
117
if packageName in self .packages :
118
- del self .packages [packageName ]
118
+ del self .packages [packageName ]
119
119
self .updatePackages ()
120
- else :
120
+ else :
121
121
print ("errore, il pacchetto " + packageName + " non è stato trovato" )
122
122
123
123
if os .path .exists ('./sounds/notes/' + packageName ):
124
- os .system ('rm -rf ./sounds/notes/' + packageName )
124
+ os .system ('rm -rf ./sounds/notes/' + packageName )
125
125
126
126
127
127
def verifyVersion (self , packageName , version ):
128
128
print ("verifica pacchetto" )
129
129
#newversionList = version.split('.')
130
+ if packageName not in this .packages :
131
+ return True
132
+
130
133
newVersionList = [int (x ) for x in version .split ('.' )]
131
134
#for i in ragen(0,len(newversionList) -1):
132
135
#newversionList[i] = int(newLversionList[i])
@@ -136,11 +139,46 @@ def verifyVersion(self, packageName, version):
136
139
137
140
for i in range (0 ,len (newVersionList ) - 1 ):
138
141
if (newVersionList [i ] > oldVersionList [i ] ):
139
- return True
142
+ return True
140
143
else if (newVersionList [i ] < oldVersionList [i ] ):
141
144
return False
142
145
143
- return False ;
146
+ return False
147
+
148
+ def addPackage (self , filename ):
149
+ pkgnames = filename .split ('_' )
150
+ version = pkgnames [1 ].replace ('.zip' , '' )
151
+ pkgname = pkgnames [0 ]
152
+ pkgpath = './sounds/notes/' + pkgname
153
+ if not self .verifyVersion (pkgname , version ):
154
+ if (version == this .package [pkgName ]['version' ]):
155
+ return 3
156
+ else :
157
+ return 2
158
+ else :
159
+
160
+ os .system ('unzip -o ' + './updatePackages/' + filename + " -d ./updatePackages" )
161
+
162
+ os .system ('mkdir ' + pkgpath )
163
+ os .system ('mv ./updatePackages/' + pkgname + "/" + 'audio.wav ' + pkgpath + '/' )
164
+
165
+ with open ('./updatePackages/' + pkgname + '/' + pkgname + '.json' ) as json_file :
166
+ print ("adding " + pkgname + " package" )
167
+ data = json .load (json_file )
168
+ for p in data ['packages' ]:
169
+ package = data ['packages' ][p ]
170
+ mp = MusicPackage (p ,package ['category' ],package ['name_IT' ],package ['name_EN' ],package ['version' ],package ['date' ])
171
+ for i in package ['interface' ]:
172
+ interfaceItem = package ['interface' ][i ]
173
+ mpi = MusicPackageInterface (i ,interfaceItem ['available' ],interfaceItem ['icon' ])
174
+ mp .addInterface (mpi )
175
+
176
+ self .packages [p ] = mp
177
+
178
+ self .updatePackages ()
179
+
180
+ os .system ('rm -rf ./updatePackages/' + pkgname )
181
+ return 1
144
182
145
183
146
184
def isPackageAvailable (self ,namePackage ):
0 commit comments