コード例 #1
0
ファイル: importer.py プロジェクト: Governa/Camelot
    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( file_name )
            movie = Movie( title = title )
            movie.cover = stored_file
            
        yield FlushSession( session )
# end create movies
# begin refresh
        yield Refresh()
コード例 #2
0
ファイル: importer.py プロジェクト: vortexR2/camelot
    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()
コード例 #3
0
ファイル: reports.py プロジェクト: klpn/arch_description
    def model_run( self, model_context ):
        templname = 'shipreport'
        outoptions = OutputOptions()
        yield ChangeObject( outoptions )
        outformat = outoptions.outformat
        of_opt = outformat_options(outformat, templname)
        select_report_file = SelectFile( of_opt['filefilter'] )
        select_report_file.existing = False
        report_filename = (yield select_report_file)[0]

        report_fullfilename = addext(report_filename, outformat)
        fileloader = FileSystemLoader(templdir)
        env = Environment(loader=fileloader)
        reporttempl = env.get_template(templname + '.md')
        archive = model_context.get_object()
        archive.voltot = 0
        serlist = natsort.natsorted(archive.series, key=lambda ser: ser.signum)
        for series in serlist:
            if series.volumes:
                series.voltot = max(vol.volno for vol in series.volumes)
                archive.voltot = archive.voltot + series.voltot
        reportsrc = reporttempl.render(archive = archive, serlist = serlist)

        convert_report(of_opt['templsetting'], of_opt['templfullname'], reportsrc,
                report_fullfilename, of_opt['pdoc_writer'])
コード例 #4
0
    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()
コード例 #5
0
ファイル: i18n.py プロジェクト: Governa/Camelot
 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') )
コード例 #6
0
 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'))
コード例 #7
0
ファイル: reports.py プロジェクト: klpn/arch_description
 def model_run( self, model_context ):
     templname = 'ead'
     filefilter = 'XML-dokument (*.xml);;Alla (*.*)'
     select_report_file = SelectFile( filefilter )
     select_report_file.existing = False
     report_filename = (yield select_report_file)[0]
     report_fullfilename = addext(report_filename, 'xml')
     fileloader = FileSystemLoader(templdir)
     env = Environment(loader=fileloader)
     reporttempl = env.get_template(templname + '.xml')
     archive = model_context.get_object()
     serlist = natsort.natsorted(archive.series, key=lambda ser: ser.signum)
     reporttempl.stream(archive = archive, serlist = serlist).dump(report_fullfilename, encoding='utf-8')
コード例 #8
0
    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)
            f = open(file_name)
            info_prof = f.readline().split(";")[:-1]
            if session.query(Profesor).filter(Profesor.username == info_prof[0]).first() != None:
                raise UserException("Exista deja profesorul "+info_prof[2])
            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.titular = prof
                    session.add(disc)
        yield FlushSession(session)
        # begin refresh
        yield Refresh()
        # end refresh
コード例 #9
0
    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()
コード例 #10
0
    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)
                disc = session.query(Discipline).filter(Discipline.disc==orar.disc).first()
                if disc:
                    orar.disciplina = disc
                    session.flush()

        yield FlushSession(session)
        # begin refresh
        yield Refresh()
        # end refresh
コード例 #11
0
ファイル: reports.py プロジェクト: klpn/arch_description
    def model_run( self, model_context ):
        objclass = model_context.get_object().__class__.__name__
        if objclass == 'Archive':
            templname = 'description'
        elif objclass == 'Creator':
            templname = 'procreport'
        outoptions = OutputOptions()
        yield ChangeObject( outoptions )
        outformat = outoptions.outformat
        of_opt = outformat_options(outformat, templname)
        select_report_file = SelectFile( of_opt['filefilter'] )
        select_report_file.existing = False
        report_filename = (yield select_report_file)[0]

        report_fullfilename = addext(report_filename, outformat)
        fileloader = FileSystemLoader(templdir)
        env = Environment(loader=fileloader)
        reporttempl = env.get_template(templname + '.md')
        logo = os.path.join(templdir, "logo")
        if objclass == 'Archive':
            archive = model_context.get_object()
            serlist = natsort.natsorted(archive.series, key=lambda ser: ser.signum)
            descpath = os.path.join(settings.CAMELOT_MEDIA_ROOT(), archive.description.name)
            with open(descpath) as descfile:
                description = unicode(descfile.read(), 'utf-8')
            reportsrc = reporttempl.render(archive = archive, serlist = serlist,
                    description = description, logo = logo)
        elif objclass == 'Creator':
            creator = model_context.get_object()
            objlist = natsort.natsorted(creator.arch_objects, key=lambda obj: obj.signum)
            divlist = natsort.natsorted(creator.divisions, key=lambda div: div.signum)
            reportsrc = reporttempl.render(creator = creator, 
                    objlist = objlist, divlist = divlist, logo = logo)

        convert_report(of_opt['templsetting'], of_opt['templfullname'], reportsrc,
                report_fullfilename, of_opt['pdoc_writer'], ['--toc'])
コード例 #12
0
ファイル: reports.py プロジェクト: klpn/arch_description
    def model_run( self, model_context ):
        templname = 'procdesc'
        outoptions = OutputOptions()
        yield ChangeObject( outoptions )
        outformat = outoptions.outformat
        of_opt = outformat_options(outformat, templname)
        select_report_file = SelectFile( of_opt['filefilter'] )
        select_report_file.existing = False
        report_filename = (yield select_report_file)[0]

        report_fullfilename = addext(report_filename, outformat)
        fileloader = FileSystemLoader(templdir)
        env = Environment(loader=fileloader)
        reporttempl = env.get_template(templname + '.md')
        logo = os.path.join(templdir, "logo")
        creator = model_context.get_object()
        descpath = os.path.join(settings.CAMELOT_MEDIA_ROOT(), creator.description.name)
        with open(descpath) as descfile:
            description = unicode(descfile.read(), 'utf-8')
        reportsrc = reporttempl.render(creator = creator, 
                description = description, logo = logo)

        convert_report(of_opt['templsetting'], of_opt['templfullname'], reportsrc,
                report_fullfilename, of_opt['pdoc_writer'])
コード例 #13
0
ファイル: reports.py プロジェクト: klpn/arch_description
    def model_run( self, model_context ):
        from reportlab.pdfgen import canvas
        from reportlab.lib.units import mm
        #import textwrap
        objclass = model_context.get_object().__class__.__name__
        
        lo = LabelOptions()
        yield ChangeObject( lo )
        filefilter = 'PDF-dokument (*.pdf);;Alla (*.*)'
        select_report_file = SelectFile( filefilter )
        select_report_file.existing = False
        report_filename = (yield select_report_file)[0]
        report_fullfilename = addext(report_filename, 'pdf')
        labelstrings_all = []
        fileloader = FileSystemLoader(templdir)
        env = Environment(loader=fileloader)
        if objclass == 'Archive':
            labeltempl = env.get_template('label.txt')
            archive = model_context.get_object()
            serlist = natsort.natsorted(archive.series, key=lambda ser: ser.signum)
            for series in serlist:
                vollist = natsort.natsorted(series.volumes, key=lambda vol: vol.volno)
                for volume in vollist:
                    curlabel = labeltempl.render(archive = archive, series = series,
                        volume = volume).replace('--', u'\u2013')
                    labelstrings_all.append(curlabel)
        elif objclass == 'Creator':
            objtempl = env.get_template('objlabel.txt')
            proctempl = env.get_template('proclabel.txt')
            typetempl = env.get_template('typelabel.txt')
            creator = model_context.get_object()
            objlist = natsort.natsorted(creator.arch_objects, key=lambda obj: obj.signum)
            for obj in objlist:
                unitlist = natsort.natsorted(obj.storage_units,
                        key=lambda unit: unit.signum)
                for unit in unitlist:
                    curlabel = objtempl.render(obj = obj, unit = unit).replace('--', u'\u2013')
                    labelstrings_all.append(curlabel)
            divlist = natsort.natsorted(creator.divisions, key=lambda div: div.signum)
            for div in divlist:
                proclist =  natsort.natsorted(div.processes, key=lambda proc: proc.signum)
                for proc in proclist:
                    unitlist = natsort.natsorted(proc.storage_units,
                        key=lambda unit: unit.signum)
                    for unit in unitlist:
                        curlabel = proctempl.render(div = div, proc = proc,
                            unit = unit).replace('--', u'\u2013')
                        labelstrings_all.append(curlabel)
                    acttypelist = natsort.natsorted(proc.acttypes, 
                            key=lambda atype: atype.signum)
                    for acttype in acttypelist:
                        unitlist = natsort.natsorted(acttype.storage_units,
                            key=lambda unit: unit.signum)
                        for unit in unitlist:
                            curlabel = typetempl.render(div = div, proc = proc,
                                    acttype = acttype, unit = unit).replace('--', u'\u2013')
                            labelstrings_all.append(curlabel)

        
        # Inspired by http://two.pairlist.net/pipermail/reportlab-users/2006-October/005401.html
        labelsize_x = lo.labelsize_x * mm
        labelsize_y = lo.labelsize_y * mm
        labelsep_x = lo.labelsep_x * mm
        labelsep_y = lo.labelsep_y * mm
        labels_xy = lo.labels_x * lo.labels_y
        papersize_x = lo.papersize_x * mm
        papersize_y = lo.papersize_y * mm
        margin_x = lo.margin_x * mm 
        margin_y = lo.margin_y * mm 
        labeltot_x = labelsize_x + labelsep_x
        labeltot_y = labelsize_y + labelsep_y
        fontsize = 10

        def chunks(l, n):
            n = max(1, n)
            return [l[i:i + n] for i in range(0, len(l), n)]
        
        labelstrings_bysheet = chunks(labelstrings_all, labels_xy)
        c = canvas.Canvas(report_fullfilename)
        c.setPageSize((papersize_x, papersize_y))

        def LabelPosition(labelord):
            y, x = divmod(labelord, lo.labels_x)
            x = margin_x + x * labeltot_x
            y = (papersize_y - margin_y) - y * labeltot_y
            return x, y
        
        for sheet in labelstrings_bysheet:
            for labelord in range(0, len(sheet)):
                x, y = LabelPosition(labelord)
                #c.rect(x, y, labelsize_x, -labelsize_y)
                labeltext = c.beginText(x+fontsize, y-2*fontsize)
                labeltext.setFont('Helvetica', fontsize, fontsize)
                labeltext.textLines(sheet[labelord])
                #labeltext.textLines(textwrap.fill(sheet[labelord], 25, 
                #    drop_whitespace = True, replace_whitespace = False))
                c.drawText(labeltext)
                    
            c.showPage()

        c.save()
コード例 #14
0
ファイル: test_action.py プロジェクト: odmsolutions/Camelot
 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 )
コード例 #15
0
ファイル: test_action.py プロジェクト: jeroendierckx/Camelot
 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 )