Functions | |
| def | config_move |
| def | config_rm |
| def | config_p05 |
| def | catalog_p05 |
| def | catalog_overlay_p05 |
| def | main_library_p05 |
| def | shopping_list_p05 |
| def | comments_p05 |
| def | backup_p05 |
| def | p05 |
| def | p05a2 |
| def | all |
| def py::qo::upgrade::all | ( | version, | ||
| notifier | ||||
| ) |
upgrade all components (config, database, etc..) since @param version
00342 : 00343 """ 00344 upgrade all components (config, database, etc..) since @param version 00345 """ 00346 qodb.admin.check_and_repair(notifier) 00347 00348 if is_version_newer("0.5,alpha1", version) : 00349 p05(notifier) 00350 elif is_version_newer("0.5,alpha2", version) : 00351 p05a2(notifier) 00352 qo.backup.restore_last() 00353 00354 if is_version_newer("0.5,beta3", version) : 00355 notifier.section(_("Converting backup files")) 00356 backup_p05(notifier) 00357 notifier.section_end() 00358 if is_version_newer("0.5,beta4", version) : 00359 qo.catalog.build_from_xml(notifier) 00360 qo.backup.restore_last() 00361 00362
| def py::qo::upgrade::backup_p05 | ( | notifier | ) |
00226 : 00227 bckdir = qocfg.get_backup_dir()+"s" 00228 if not os.path.isdir(bckdir) : 00229 return 00230 00231 reg = re.compile( "^bck_(\d{8})(\d{6})-(\d+)\.tar\.bz2$" ) 00232 library_main_library = qodb.models.Library.objects.get(id=qodb.cte.main_library_id) 00233 library_shopping_list = qodb.models.Library.objects.get(id=qodb.cte.shopping_list_id) 00234 for bckfile in filter(lambda x: x.endswith(".tar.bz2"), sorted(os.listdir(bckdir))) : 00235 m = reg.match(bckfile) 00236 if not m : 00237 continue 00238 bckname = "backup_%s_%s" % (m.group(1), m.group(2)) 00239 try : 00240 src = tarfile.open(os.path.join(bckdir, bckfile), "r:bz2") 00241 sp = qo.backup.savepoint(bckname, "w") 00242 00243 # 00244 # overlay 00245 # 00246 00247 params = [ 00248 ("author", "author.xml", "AUTHOR", {"id":"qoid", "name":"name"}), 00249 ("editor", "editor.xml", "EDITOR", {"id":"qoid", "name":"name", "web_uri":"homepage"}), 00250 ("collection", "collection.xml", "COLLECTION", {"id":"qoid", "name":"name", "editor":"editor"}), 00251 ("series", "series.xml", "ASERIES", {"id":"qoid", "name":"name", "collection":"collection"}), 00252 ("album", "comics.xml", "COMIC", {"id":"qoid", "name":"name", "series":"series", 00253 "author": "authors_raw", 'drawer': 'drawers_raw', 00254 'volume': 'volume', 'date': 'published_date', 00255 'isbn': 'isbn', 'ean': 'ean', 'guiding_price': 'guiding_price'}), 00256 ] 00257 00258 for name, srcname, srcename, attrmap in params : 00259 doc = qo.xmlutil.create_document("catalog") 00260 docsrc = xml.dom.minidom.parse(src.extractfile(srcname)) 00261 00262 for esrc in docsrc.getElementsByTagName(srcename) : 00263 element = doc.createElement(name) 00264 for asrc in attrmap.keys() : 00265 if esrc.hasAttribute(asrc) : 00266 element.setAttribute(attrmap[asrc], esrc.getAttribute(asrc)) 00267 doc.documentElement.appendChild(element) 00268 00269 sp.push(name+".xml", doc) 00270 00271 # 00272 # libraries 00273 # 00274 doc = qo.xmlutil.create_document("libraries") 00275 00276 copyid = 1 00277 00278 docsrc = xml.dom.minidom.parse(src.extractfile("my_collection.xml")) 00279 library = library_main_library 00280 root = doc.createElement("library") 00281 root.setAttribute("name", library.name) 00282 root.setAttribute("type", str(library.type)) 00283 doc.documentElement.appendChild(root) 00284 00285 for esrc in docsrc.getElementsByTagName("MY") : 00286 element = doc.createElement("albumcopy") 00287 element.setAttribute("copyid", str(copyid)) 00288 element.setAttribute("album", esrc.getAttribute("ref")) 00289 root.appendChild(element) 00290 copyid += 1 00291 00292 docsrc = xml.dom.minidom.parse(src.extractfile("shopping_list.xml")) 00293 library = library_shopping_list 00294 root = doc.createElement("library") 00295 root.setAttribute("name", library.name) 00296 root.setAttribute("type", str(library.type)) 00297 doc.documentElement.appendChild(root) 00298 00299 for esrc in docsrc.getElementsByTagName("COMICS") : 00300 element = doc.createElement("albumcopy") 00301 element.setAttribute("copyid", str(copyid)) 00302 element.setAttribute("album", esrc.getAttribute("ref")) 00303 root.appendChild(element) 00304 copyid += 1 00305 00306 sp.push("libraries.xml", doc) 00307 00308 sp.flush() 00309 except : 00310 traceback.print_exc() 00311 00312 @qodb.transaction.commit_on_success def p05( notifier ) :
| def py::qo::upgrade::catalog_overlay_p05 | ( | ) |
import xml overlays
00080 : 00081 """ 00082 import xml overlays 00083 """ 00084 from qodb.models import Editor, Collection, Series 00085 00086 def extract_authors( value ) : 00087 return sorted(value.split(" ")) 00088 00089 def safe_conv( value, ctor, default ) : 00090 """ 00091 returns ctor(value) if value is non-empty, default else 00092 """ 00093 if value.strip() == "" : 00094 return default 00095 return ctor(value) 00096 00097 def safe_float( value ) : 00098 return safe_conv(value, float, .0) 00099 def safe_int( value ) : 00100 return safe_conv(value, int, 0) 00101 00102 map_prop_from_attr = { 00103 "AUTHOR" : { 00104 "id" : ("qoid",None), 00105 }, 00106 "EDITOR" : { 00107 "id" : ("qoid",None), 00108 "web_uri" : ("homepage",None), 00109 }, 00110 "COLLECTION" : { 00111 "id" : ("qoid",None), 00112 "editor" : ("editor",lambda qoid: Editor.objects.get(qoid=qoid)), 00113 }, 00114 "ASERIES" : { 00115 "id" : ("qoid",None), 00116 "collection" : ("collection",lambda qoid: Collection.objects.get(qoid=qoid)), 00117 }, 00118 "COMIC" : { 00119 "id" : ("qoid",None), 00120 "series" : ("series",lambda qoid: Series.objects.get(qoid=qoid)), 00121 "date" : ("published_date",None), 00122 "volume" : ("volume",safe_int), 00123 "author" : ("authors",extract_authors), 00124 "drawer" : ("drawers",extract_authors), 00125 "guiding_price" : ("guiding_price",safe_float), 00126 } 00127 } 00128 00129 def extract_attrs( node ) : 00130 def prop_from_attr( (attname,attvalue) ) : 00131 attname, make = map_prop_from_attr.get(node.localName,{}).get(attname,(str(attname),None)) 00132 if make : 00133 attvalue = make(attvalue) 00134 return attname, attvalue 00135 return dict(map(prop_from_attr,node.attributes.items())) 00136 00137 for file in qo.catalog.sort_by_dependencies(filter(os.path.isfile, qocfg.get_overlay_files())) : 00138 try : 00139 doc = xml.dom.minidom.parse(file) 00140 except : 00141 traceback.print_exc() 00142 continue 00143 for node in doc.documentElement.childNodes : 00144 if node.nodeType is not xml.dom.Node.ELEMENT_NODE : 00145 continue 00146 qo.catalog.model_from_xml[node.localName].make_overlay(**extract_attrs(node)) 00147 00148 00149 @qodb.transaction.commit_on_success def main_library_p05() :
| def py::qo::upgrade::catalog_p05 | ( | notifier | ) |
00076 : 00077 qo.catalog.build_from_xml(notifier) 00078 00079 @qodb.transaction.commit_on_success def catalog_overlay_p05() :
| def py::qo::upgrade::comments_p05 | ( | ) |
import comments
00214 : 00215 """ 00216 import comments 00217 """ 00218 datadir = os.path.join(qocfg.USER["dir"],"data") 00219 def is_comment( filename ) : 00220 return filename.endswith("#comment.txt") and filename.count("#") == 1 00221 for filename in filter(is_comment, os.listdir(datadir)) : 00222 qoid, _ = filename.split("#") 00223 shutil.copyfile(os.path.join(datadir, filename), qocfg.get_comment_path(qoid)) 00224 00225 def backup_p05( notifier ) :
| def py::qo::upgrade::config_move | ( | from_section, | ||
| from_option, | ||||
| to_section, | ||||
| to_option, | ||||
transform = lambda x: x, |
||||
method = ("get","set" | ||||
| ) |
move a config option
00039 : x, method = ("get","set") ) : 00040 """ 00041 move a config option 00042 """ 00043 cfg = qocfg.USER["config"] 00044 if not cfg.has_option(from_section,from_option) : 00045 return 00046 if not cfg.has_option(to_section,to_option) : 00047 if to_section != from_section : 00048 if not cfg.has_section(to_section) : 00049 cfg.add_section(to_section) 00050 getattr(cfg,method[1])(to_section,to_option,transform(getattr(cfg,method[0])(from_section,from_option))) 00051 cfg.remove_option(from_section,from_option) 00052 if to_section != from_section and len(cfg.options(from_section)) == 0 : 00053 cfg.remove_section(from_section) 00054
| def py::qo::upgrade::config_p05 | ( | ) |
00063 : 00064 config_move("Colors","my","Colors","library%d"%qodb.cte.main_library_id) 00065 config_move("Colors","shopping_list","Colors","library%d"%qodb.cte.shopping_list_id) 00066 config_move("ui/qt","main_geometry","gui/main_window","geometry") 00067 config_move("ui/qt","column_latest_geometry","gui/latestout","geometry") 00068 config_move("ui/qt","column_my_geometry","gui/main_library","geometry") 00069 config_move("ui/qt","column_next_geometry","gui/nextout","geometry") 00070 config_move("ui/qt","column_series_geometry","gui/main_library_series","geometry") 00071 config_move("ui/qt","column_shopping_geometry","gui/shopping_list","geometry") 00072 config_move("ui/qt","column_catalog_geometry", "gui/catalog", "geometry") 00073 config_rm("General","webbrowser") 00074 qocfg.cfg.setboolean("General","configured",True) 00075 def catalog_p05( notifier ) :
| def py::qo::upgrade::config_rm | ( | section, | ||
| option | ||||
| ) |
00055 : 00056 if qocfg.cfg.has_option(section, option) : 00057 qocfg.cfg.remove_option(section, option) 00058 00059 # 00060 # upgrade for versions prior to 0.5 (django transition) 00061 # 00062 def config_p05() :
| def py::qo::upgrade::main_library_p05 | ( | ) |
import xml collection into qodb main library
00150 : 00151 """ 00152 import xml collection into qodb main library 00153 """ 00154 orig_file = os.path.join(qocfg.USER["dir"],"my_collection.xml") 00155 if not os.path.exists(orig_file) : 00156 return 00157 00158 try : 00159 doc = xml.dom.minidom.parse(orig_file) 00160 except : 00161 traceback.print_exc() 00162 return 00163 00164 from qodb.models import Library, AlbumCopy, Album 00165 lib = Library.objects.get(id=qodb.cte.main_library_id) 00166 00167 for album in doc.getElementsByTagName("MY") : 00168 # get Album reference 00169 try : 00170 a = Album.objects.get(qoid=album.getAttribute("ref")) 00171 except Album.DoesNotExist : 00172 print "no such album: %s" % album.getAttribute("ref") 00173 continue 00174 00175 # create album copy 00176 c = AlbumCopy(library=lib,album=a,original_edition=False) 00177 00178 # user comment 00179 comment_file = os.path.join(qocfg.USER["dir"],"data","%s#comment.txt"%qo.utils.encode(album.getAttribute("id"))) 00180 if os.path.exists( comment_file ) : 00181 c.description = open(comment_file).read() 00182 c.save() 00183 00184 00185 @qodb.transaction.commit_on_success def shopping_list_p05() :
| def py::qo::upgrade::p05 | ( | notifier | ) |
upgrade from prior to 0.5
00313 : 00314 """ 00315 upgrade from prior to 0.5 00316 """ 00317 config_p05() 00318 catalog_p05(notifier) 00319 notifier.grow(4) 00320 notifier.section(_("Import data")) 00321 comments_p05() 00322 notifier.section_end() 00323 notifier.section(_("Import catalog overlay")) 00324 catalog_overlay_p05() 00325 notifier.section_end() 00326 notifier.section(_("Import user library")) 00327 main_library_p05() 00328 notifier.section_end() 00329 notifier.section(_("Import user shopping list")) 00330 shopping_list_p05() 00331 notifier.section_end() 00332 def p05a2( notifier ) :
| def py::qo::upgrade::p05a2 | ( | notifier | ) |
00333 : 00334 import qodb.upgrade 00335 qodb.upgrade.upgrade_to_0(notifier) 00336 00337 # 00338 # 00339 # 00340 00341 @qodb.transaction.commit_on_success def all( version, notifier ) :
| def py::qo::upgrade::shopping_list_p05 | ( | ) |
import xml shopping list into qodb shopping list
00186 : 00187 """ 00188 import xml shopping list into qodb shopping list 00189 """ 00190 orig_file = os.path.join(qocfg.USER["dir"],"shopping_list.xml") 00191 if not os.path.exists(orig_file) : 00192 return 00193 00194 import xml.dom.minidom 00195 try : 00196 doc = xml.dom.minidom.parse(orig_file) 00197 except : 00198 traceback.print_exc() 00199 return 00200 00201 from qodb.models import Library, AlbumCopy, Album 00202 lib = Library.objects.get(id=qodb.cte.shopping_list_id) 00203 00204 for album in doc.getElementsByTagName("COMICS") : 00205 # get Album reference 00206 try : 00207 a = Album.objects.get(qoid=album.getAttribute("ref")) 00208 except Album.DoesNotExist : 00209 print "no such album: %s" % album.getAttribute("ref") 00210 continue 00211 00212 lib.albums.create(album=a, original_edition=False) 00213 def comments_p05() :
1.5.3