28
28
29
29
import json
30
30
import os
31
+ import logging
32
+ import copy
31
33
32
34
class MusicPackage :
33
35
34
- def __init__ (self , nameID , category , name_IT ,n ame_EN , version , date ):
36
+ def __init__ (self , nameID , category , name_IT , name_EN , version , date ):
35
37
self .nameID = nameID
36
38
self .category = category
37
39
self .name_IT = name_IT
@@ -87,7 +89,6 @@ class MusicPackageManager:
87
89
def get_instance (cls ):
88
90
if cls ._instance is None :
89
91
cls ._instance = MusicPackageManager ()
90
- print ("make MusicPackageManager" )
91
92
return cls ._instance
92
93
93
94
def __init__ (self ):
@@ -107,7 +108,14 @@ def __init__(self):
107
108
self .packages [p ] = mp
108
109
109
110
def listPackages (self ):
110
- return self .packages
111
+ packages_serializable = dict ()
112
+ for name , package in self .packages .items ():
113
+ package_copy = copy .deepcopy (package )
114
+ packages_serializable [name ] = package_copy .__dict__
115
+ packages_serializable [name ]['interfaces' ] = []
116
+ for i in package .interfaces :
117
+ packages_serializable [name ]['interfaces' ].append (i .__dict__ )
118
+ return packages_serializable
111
119
112
120
def updatePackages (self ):
113
121
newdict = { 'packages' : {} }
@@ -128,25 +136,26 @@ def updatePackages(self):
128
136
newdict ['packages' ][nameID ]['interface' ]['advanced' ]['icon' ] = self .packages [element ].getInterfaces ()[2 ].getIcon ()
129
137
130
138
#json_packages = json.dumps(newdict)
131
- with open ('./dist/static /music_package.json' , 'w' , encoding = 'utf-8' ) as json_file :
139
+ with open ('sounds/notes /music_package.json' , 'w' , encoding = 'utf-8' ) as json_file :
132
140
json .dump (newdict , json_file , ensure_ascii = False , indent = 4 )
133
141
134
142
135
143
def deletePackage (self , packageName ):
136
- if packageName in self .packages :
137
- del self .packages [packageName ]
138
- self .updatePackages ()
139
- else :
140
- print ("errore, il pacchetto " + packageName + " non è stato trovato" )
141
- return 2
144
+ logging .info ("packageName: " + packageName )
145
+ if packageName in self .packages :
146
+ del self .packages [packageName ]
147
+ self .updatePackages ()
148
+ else :
149
+ logging .error ("errore, il pacchetto " + packageName + " non è stato trovato" )
150
+ return 2
142
151
143
- if os .path .exists ('./sounds/notes/' + packageName ):
144
- os .system ('rm -rf ./sounds/notes/' + packageName )
145
- return 1
152
+ if os .path .exists ('./sounds/notes/' + packageName ):
153
+ os .system ('rm -rf ./sounds/notes/' + packageName )
154
+ return 1
146
155
147
156
148
157
def verifyVersion (self , packageName , version ):
149
- print ("verifica pacchetto" )
158
+ logging . info ("verifica pacchetto" )
150
159
#newversionList = version.split('.')
151
160
if packageName not in self .packages :
152
161
return True
@@ -169,15 +178,15 @@ def verifyVersion(self, packageName, version):
169
178
def addPackage (self , filename ):
170
179
pkgnames = filename .split ('_' )
171
180
version = pkgnames [1 ].replace ('.zip' , '' )
172
- print ( version )
181
+ logging . info ( "Music Package version: " + version )
173
182
pkgname = pkgnames [0 ]
174
183
pkgpath = './sounds/notes/' + pkgname
175
184
if not self .verifyVersion (pkgname , version ):
176
185
if (version == self .packages [pkgname ].getVersion ()):
177
- print ("errore, il pacchetto " + pkgname + " ha versione identica a quello attualmente installato" )
186
+ logging . error ("errore, il pacchetto " + pkgname + " ha versione identica a quello attualmente installato" )
178
187
return 3
179
188
else :
180
- print ("errore, il pacchetto " + pkgname + " ha versione precendente a quello attualmente installato" )
189
+ logging . info ("errore, il pacchetto " + pkgname + " ha versione precendente a quello attualmente installato" )
181
190
return 2
182
191
else :
183
192
@@ -187,7 +196,7 @@ def addPackage(self, filename):
187
196
os .system ('mv ./updatePackages/' + pkgname + "/" + 'audio.wav ' + pkgpath + '/' )
188
197
189
198
with open ('./updatePackages/' + pkgname + '/' + pkgname + '.json' ) as json_file :
190
- print ("adding " + pkgname + " package" )
199
+ logging . info ("adding " + pkgname + " package" )
191
200
data = json .load (json_file )
192
201
for p in data ['packages' ]:
193
202
package = data ['packages' ][p ]
0 commit comments