def insert_file(self, filename): assert lessonfile.is_uri(filename) or os.path.isabs(filename) self.conn.execute("insert into lessonfiles " "(filename, hash) " "values (?, ?)", (filename, hash_of_lessonfile(filename))) return self.get_fileid(filename)
def _practise_lessonfile(self, filename, urlobj=None): """ return the module name. """ module = lessonfile.infocache.get(filename, 'module') if self.m_running_exercise: solfege.win.box_dict[self.m_running_exercise].on_end_practise() if not lessonfile.is_uri(filename): # Since the file is in ~/.solfege/exercises we must check # if the user have written his own exercise module if os.path.exists(os.path.normpath(os.path.join( os.path.dirname(filename), "..", "modules", "%s.py" % module))): module = "user:%s/%s" % ( os.path.dirname(filename).split(os.sep)[-2], module) if module not in self.m_teachers: self.create_teacher(module) if module not in solfege.win.box_dict: solfege.win.initialise_exercise(self.m_teachers[module]) self.m_teachers[module].set_lessonfile(filename) if self.m_teachers[module].m_P: solfege.win.activate_exercise(module, urlobj) self.m_running_exercise = module self.m_teachers[module].g_view = solfege.win.box_dict[module] solfege.win.show_help_on_current() return module
def _practise_lessonfile(self, filename, urlobj=None): """ return the module name. """ module = lessonfile.infocache.get(filename, 'module') if self.m_running_exercise: solfege.win.box_dict[self.m_running_exercise].on_end_practise() if not lessonfile.is_uri(filename): # Since the file is in ~/.solfege/exercises we must check # if the user have written his own exercise module if os.path.exists( os.path.normpath( os.path.join(os.path.dirname(filename), "..", "modules", u"%s.py" % module))): module = u"user:%s/%s" % (os.path.dirname(filename).split( os.sep)[-2], module) if module not in self.m_teachers: self.create_teacher(module) if module not in solfege.win.box_dict: solfege.win.initialise_exercise(self.m_teachers[module]) self.m_teachers[module].set_lessonfile(filename) if self.m_teachers[module].m_P: solfege.win.activate_exercise(module, urlobj) self.m_running_exercise = module self.m_teachers[module].g_view = solfege.win.box_dict[module] solfege.win.show_help_on_current() return module
def _practise_lessonfile(self, filename, urlobj=None): """ return the module name. If the module is a solfege builtin module, the name is just the filename without .py ext, for example "idbyname" If the file is saved in USERFILES/exercises/dirname/lesson-files/ it is named "user:dirname/modulename" """ # call normpath os fix paths\\like/this to only have # one sort of separator filename = os.path.normpath(filename) module = lessonfile.infocache.get(filename, 'module') if self.m_running_exercise: solfege.win.box_dict[self.m_running_exercise].on_end_practise() if not lessonfile.is_uri(filename): # Since the file is in ~/.solfege/exercises we must check # if the user have written his own exercise module if os.path.exists( os.path.normpath( os.path.join(os.path.dirname(filename), "..", "modules", "%s.py" % module))): module = "user:%s/%s" % (os.path.dirname(filename).split( os.sep)[-2], module) if module not in self.m_teachers: self.create_teacher(module) if module not in solfege.win.box_dict: solfege.win.initialise_exercise(self.m_teachers[module]) self.m_teachers[module].set_lessonfile(filename) if self.m_teachers[module].m_P: solfege.win.activate_exercise(module, urlobj) self.m_running_exercise = module self.m_teachers[module].g_view = solfege.win.box_dict[module] solfege.win.show_help_on_current() return module
def get_fileid(self, filename): assert lessonfile.is_uri(filename) or os.path.isabs(filename), filename row = self.conn.execute( "select fileid from lessonfiles " "where filename=?", (filename, )).fetchone() if row: return row[0] else: raise self.FileNotInDB(filename)
def get_fileid(self, filename): assert lessonfile.is_uri(filename) or os.path.isabs(filename), filename row = self.conn.execute( "select fileid from lessonfiles " "where filename=?", (filename,)).fetchone() if row: return row[0] else: raise self.FileNotInDB(filename)
def mk_abs(filename, save_location): if not lessonfile.is_uri(filename) and not os.path.isabs(filename): return os.path.join(save_location, filename) return filename