def model_run( self, model_context ): from camelot.view.action_steps import ( SelectFile, UpdateProgress, Refresh, FlushSession ) select_image_files = SelectFile( 'Image Files (*.png *.jpg);;All Files (*)' ) select_image_files.single = False file_names = yield select_image_files file_count = len( file_names ) # end select files # begin create movies import os from sqlalchemy import orm from camelot.core.orm import Session from camelot_example.model import Movie movie_mapper = orm.class_mapper( Movie ) cover_property = movie_mapper.get_property( 'cover' ) storage = cover_property.columns[0].type.storage session = Session() for i, file_name in enumerate(file_names): yield UpdateProgress( i, file_count ) title = os.path.splitext( os.path.basename( file_name ) )[0] stored_file = storage.checkin( six.text_type( file_name ) ) movie = Movie( title = six.text_type( title ) ) movie.cover = stored_file yield FlushSession( session ) # end create movies # begin refresh yield Refresh()
def model_run(self, model_context): from camelot.view.action_steps import (SelectFile, UpdateProgress, Refresh, FlushSession) select_files = SelectFile('Txt Files (*.txt *.csv);;All Files (*)') select_files.single = False file_names = yield select_files file_count = len(file_names) import os from camelot.core.orm import Session from rms.Model.Orar import Orar session = Session() for i, file_name in enumerate(file_names): yield UpdateProgress(i, file_count) title = os.path.splitext(os.path.basename(file_name))[0] print(file_name) for line in open(file_name): vals = line.split(';')[:-1] if len(vals) != 8: raise ImportException("Fisierul nu e dat bine") if vals[2] not in ['0', '1', '2']: raise ImportException("Frecventa nu e data bine") print(vals) orar = Orar(*vals) print(orar) session.add(orar) yield FlushSession(session) # begin refresh yield Refresh()
def model_run(self, model_context): from camelot.view.action_steps import SelectFile select_file = SelectFile() select_file.existing = False filenames = yield select_file for filename in filenames: file = open(filename, 'w') for translation in model_context.get_collection(): file.write( (u'msgid "%s"\n' % translation.source).encode('utf-8')) file.write( (u'msgstr "%s"\n\n' % translation.value).encode('utf-8'))
def model_run(self, model_context): from camelot.view.action_steps import (SelectFile, UpdateProgress, Refresh, FlushSession) select_files = SelectFile('Txt Files (*.txt *.csv);;All Files (*)') select_files.single = False file_names = yield select_files file_count = len(file_names) import os from camelot.core.orm import Session from rms.Model.ResurseUmane import ResurseUmane from rms.Model.Discipline import Discipline from rms.Model.OreSuplimentare import OreSuplimentare session = Session() for i, file_name in enumerate(file_names): yield UpdateProgress(i, file_count) print(file_name) f = open(file_name) info_prof = f.readline().split(";")[:-1] print(info_prof) prof = Profesor(*info_prof) session.add(prof) for line in f: if line[-1] == ';': vals = line[:-1].split(',') else: vals = line[:-2].split(',') print(vals) try: vals[0] = int(vals[0]) oresup = OreSuplimentare(*vals) oresup.profesor = prof session.add(oresup) except ValueError: disc = Discipline(*vals) disc.profesor = prof session.add(disc) yield FlushSession(session) # begin refresh yield Refresh()
def test_select_file( self ): from camelot.view.action_steps import SelectFile select_file = SelectFile( 'Image Files (*.png *.jpg);;All Files (*)' ) dialog = select_file.render() self.grab_widget( dialog )