~ubuntu-branches/ubuntu/raring/mnemosyne/raring

« back to all changes in this revision

Viewing changes to mnemosyne/libmnemosyne/databases/SQLite.py

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2013-04-18 20:43:08 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20130418204308-tiwzzs0n1n79qhyt
Tags: 2.2.1-0ubuntu1
New upstream bugfix release (LP: #1169634)

Show diffs side-by-side

added added

removed removed

Lines of Context:
272
272
        return self._path
273
273
 
274
274
    def name(self):
275
 
        return os.path.basename(self.config()["last_database"])
 
275
        return os.path.basename(self._path)
276
276
 
277
277
    def display_name(self):
278
278
        if not self.is_loaded():
279
279
            return None
280
280
        else:
281
 
            return os.path.basename(self.config()["last_database"]).\
282
 
                   split(self.database().suffix)[0]
 
281
            return os.path.basename(self._path).\
 
282
                split(self.database().suffix)[0]
283
283
 
284
284
    def compact(self):
285
285
        self.con.execute("vacuum")
304
304
            values(?,?)""", ("log.txt", 0))
305
305
        self.config()["last_database"] = \
306
306
            contract_path(self._path, self.config().data_dir)
307
 
        # Create __UNTAGGED__ tag
 
307
        # Create __UNTAGGED__ tag.
308
308
        tag = Tag("__UNTAGGED__", "__UNTAGGED__")
309
309
        self.add_tag(tag)
310
310
        # Create default criterion.
337
337
        if self.is_loaded():
338
338
            self.unload()
339
339
        self._path = expand_path(path, self.config().data_dir)
340
 
        self.create_media_dir_if_needed()
341
340
        # Check database version.
342
341
        try:
343
342
            sql_res = self.con.execute("""select value from global_variables
345
344
        except:
346
345
            raise RuntimeError, _("Unable to load file.") + traceback_string()
347
346
        if sql_res is None:
348
 
            raise RuntimeError, _("Unable to load file, query failed")
 
347
            raise RuntimeError, _("Unable to load file, query failed.")
349
348
        if sql_res[0] != self.version:
350
349
            raise RuntimeError, \
351
350
                _("Unable to load file: database version mismatch.")
 
351
        self.create_media_dir_if_needed()
352
352
        # Upgrade.
353
353
        self.con.execute("""create index if not exists
354
354
            i_cards_3 on cards (_fact_id);""")
569
569
                criterion.id != "__DEFAULT__":
570
570
                saved_criterion = criterion
571
571
                break
 
572
        # If there is no explictly named criterion, we always activate the
 
573
        # tag except when a parent is inactive.
572
574
        if not saved_criterion:
573
575
            criteria_to_activate_tag_in = [current_criterion]
 
576
            existing_tag_for_name = {tag.name : tag for tag in self.tags()}
 
577
            partial_tag_name = ""
 
578
            for node in tag.name.split("::"):
 
579
                partial_tag_name += node
 
580
                if partial_tag_name != tag.name and \
 
581
                    partial_tag_name in existing_tag_for_name:
 
582
                    parent = existing_tag_for_name[partial_tag_name]
 
583
                    if not current_criterion.is_tag_active(parent):
 
584
                        criteria_to_activate_tag_in = []
 
585
                        break
 
586
                partial_tag_name += "::"
 
587
        # If there is a saved criterion active, we ask the user what to do.
574
588
        else:
575
589
            answer = self.main_widget().show_question(\
576
590
                _("Make tag '%s' active in saved set '%s'?") % \