コード例 #1
0
ファイル: io.py プロジェクト: gzt200361/ThirdParty-2.0.0
def save_log_to_xml(log, filename):
    daoList = getVersionDAO(currentVersion)
    tags = {'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
            'xsi:schemaLocation': 'http://www.vistrails.org/log.xsd'
            }
    daoList.save_to_xml(log, filename, tags, currentVersion)
    return log
コード例 #2
0
ファイル: io.py プロジェクト: gzt200361/ThirdParty-2.0.0
def open_workflow_from_xml(filename):
    """open_workflow_from_xml(filename) -> DBWorkflow"""
    tree = ElementTree.parse(filename)
    version = get_version_for_xml(tree.getroot())
    daoList = getVersionDAO(version)
    workflow = daoList.open_from_xml(filename, DBWorkflow.vtType)
    workflow = translateWorkflow(workflow, version)
    db.services.workflow.update_id_scope(workflow)
    return workflow
コード例 #3
0
ファイル: io.py プロジェクト: gzt200361/ThirdParty-2.0.0
def open_log_from_xml(filename):
    """open_log_from_xml(filename) -> DBLog"""
    tree = ElementTree.parse(filename)
    version = get_version_for_xml(tree.getroot())
    daoList = getVersionDAO(version)
    log = daoList.open_from_xml(filename, DBLog.vtType)
    log = translateLog(log, version)
    db.services.log.update_id_scope(log)
    return log
コード例 #4
0
ファイル: io.py プロジェクト: gzt200361/ThirdParty-2.0.0
def save_vistrail_to_zip_xml(vistrail, filename):
    """save_vistrail_to_zip_xml(vistrail: Vistrail, filename:str)-> None
    Generate a zip compressed version of vistrail.
    It raise an Exception if there was an error
    
    """

    (file_, xmlfname) = tempfile.mkstemp(suffix='.xml')

    os.close(file_)
    save_vistrail_to_xml(vistrail,xmlfname)
    vt_fname = os.path.join(os.path.dirname(xmlfname), 'vistrail')
    os.rename(xmlfname, vt_fname)
    zip_fnames = [vt_fname, ]

    if vistrail.log is not None and len(vistrail.log.workflow_execs) > 0:
        if vistrail.log_filename is None:
            (log_file, log_filename) = tempfile.mkstemp(suffix='.xml')
            os.close(log_file)
            log_file = open(log_filename, "wb")
        else:
            log_filename = vistrail.log_filename
            log_file = open(log_filename, 'ab')

        print "+++ ", log_filename
        print "*** ", log_file
        if not hasattr(log_file, "write"):
            print "no!!!"
        
        # append log to log_file
        for workflow_exec in vistrail.log.workflow_execs:
            daoList = getVersionDAO(currentVersion)
            daoList.save_to_xml(workflow_exec, log_file, {}, currentVersion)
        log_file.close()

        log_fname = os.path.join(os.path.dirname(log_filename), 'log')
        os.rename(log_filename, log_fname)
        zip_fnames.append(log_fname)

#     name_in_archive = os.path.join(os.path.dirname(xmlfname),'vistrail')
#     os.rename(xmlfname,name_in_archive)

    core.requirements.require_executable('zip')
    output = []
    cmdline = ['zip', '-r', '-j', '-q', filename] + zip_fnames
    result = execute_cmdline(cmdline,output)
    
    #print result, output
    for fname in zip_fnames:
        os.unlink(fname)
    if result != 0 and len(output) != 0:
        for line in output:
            if line.find('deflated') == -1:
                raise Exception(" ".join(output))

    return vistrail
コード例 #5
0
ファイル: io.py プロジェクト: gzt200361/ThirdParty-2.0.0
def open_vistrail_from_xml(filename):
    """open_vistrail_from_xml(filename) -> Vistrail"""
    tree = ElementTree.parse(filename)
    version = get_version_for_xml(tree.getroot())
    try:
        daoList = getVersionDAO(version)
        vistrail = daoList.open_from_xml(filename, DBVistrail.vtType)
        vistrail = translateVistrail(vistrail, version)
        db.services.vistrail.update_id_scope(vistrail)
    except VistrailsDBException, e:
        msg = "This vistrail was created by a newer version of VisTrails "
        msg += "and cannot be opened."
        raise VistrailsDBException(msg)
コード例 #6
0
ファイル: io.py プロジェクト: gzt200361/ThirdParty-2.0.0
def write_sql_objects(db_connection, objectList, do_copy=False, 
                      global_props=None):
    dao_list = getVersionDAO(currentVersion)

    for object in objectList:
        children = object.db_children() # forSQL=True)
        children.reverse()
        if global_props is None:
            global_props = {'entity_type': "'" + object.vtType + "'"}
        # print 'global_props:', global_props

        # assumes not deleting entire thing
        (child, _, _) = children[0]
        dao_list['sql'][child.vtType].set_sql_columns(db_connection, child, 
                                                      global_props, do_copy)
        dao_list['sql'][child.vtType].to_sql_fast(child, do_copy)
        if not do_copy:
            for (child, _, _) in children:
                for obj in child.db_deleted_children(True):
                    dao_list['sql'][obj.vtType].delete_sql_column(db_connection,
                                                                  obj,
                                                                  global_props)

        (child, _, _) = children.pop(0)
        child.is_dirty = False
        child.is_new = False
        for (child, _, _) in children:
            # print "child:", child.vtType, child.db_id
            dao_list['sql'][child.vtType].set_sql_columns(db_connection, child, 
                                                          global_props, do_copy)
            dao_list['sql'][child.vtType].to_sql_fast(child, do_copy)
            if child.vtType == DBGroup.vtType:
                if child.db_workflow:
                    # print '*** entity_type:', global_props['entity_type']
                    write_sql_objects(db_connection, [child.db_workflow],
                                      do_copy,
                                      {'entity_id': global_props['entity_id'],
                                       'entity_type': \
                                           global_props['entity_type']}
                                      )
                                            
            child.is_dirty = False
            child.is_new = False
コード例 #7
0
ファイル: io.py プロジェクト: gzt200361/ThirdParty-2.0.0
def read_sql_objects(db_connection, vtType, id, lock=False):
    dao_list = getVersionDAO(currentVersion)

    all_objects = {}
    res = []
    global_props = {'id': id}
    # print global_props
    res_objects = dao_list['sql'][vtType].get_sql_columns(db_connection, 
                                                          global_props,
                                                          lock)
    all_objects.update(res_objects)
    res = res_objects.values()
    del global_props['id']

    for dao in dao_list['sql'].itervalues():
        if (dao == dao_list['sql'][DBVistrail.vtType] or
            # dao == dao_list['sql'][DBWorkflow.vtType] or
            dao == dao_list['sql'][DBLog.vtType] or
            dao == dao_list['sql'][DBAbstraction.vtType]):
            continue
        current_objs = dao.get_sql_columns(db_connection, global_props, lock)
        if dao == dao_list['sql'][DBWorkflow.vtType]:
            for key, obj in current_objs.iteritems():
                if key[0] == vtType and key[1] == id:
                    continue
                elif key[0] == DBWorkflow.vtType:
                    res_objs = \
                        read_sql_objects(db_connection, key[0], key[1], lock)
                    res_dict = {}
                    for res_obj in res_objs:
                        res_dict[(res_obj.db_id, res_obj.vtType)] = res_obj
                    all_objects.update(res_dict)
        else:
            all_objects.update(current_objs)

    for key, obj in all_objects.iteritems():
        if key[0] == vtType and key[1] == id:
            continue
        dao_list['sql'][obj.vtType].from_sql_fast(obj, all_objects)
    for obj in all_objects.itervalues():
        obj.is_dirty = False
        obj.is_new = False
    return res
コード例 #8
0
ファイル: io.py プロジェクト: gzt200361/ThirdParty-2.0.0
def unserialize(str, obj_type):
    daoList = getVersionDAO(currentVersion)
    return daoList.unserialize(str, obj_type)
コード例 #9
0
ファイル: io.py プロジェクト: gzt200361/ThirdParty-2.0.0
def serialize(object):
    daoList = getVersionDAO(currentVersion)
    return daoList.serialize(object)
コード例 #10
0
def new_save_vistrail_to_zip_xml(vistrail, filename):
    # Dumb hack to figure out if we are autosaving 
    if filename.find('vt_autosaves') > 0:
        getBuilderWindow().startProgress('Autosaving...')
    else:
        getBuilderWindow().startProgress('Saving...')

    # Write the vistrail file to disk
    (file_, xmlfname) = tempfile.mkstemp(suffix='.xml')
    os.close(file_)
    save_vistrail_to_xml(vistrail,xmlfname)
    vt_fname = os.path.join(os.path.dirname(xmlfname), 'vistrail')
    if os.path.exists(vt_fname):
        os.remove(vt_fname)
    os.rename(xmlfname, vt_fname)
    zip_fnames = [vt_fname, ]

    #Audio Dir
    ###################################################
    zip_audio_folder = []
    audio_dir = vistrail.db_audio_dir
    zip_audio_folder.append(audio_dir)
    ###################################################
    #Video Dir
    ###################################################
    zip_video_folder = []
    video_dir = vistrail.db_video_dir
    zip_video_folder.append(video_dir)
    ###################################################

    getBuilderWindow().updateProgress(0.2)

    # Save binary data
    (bin_file, bin_filename) = tempfile.mkstemp(suffix='.bin')
    os.close(bin_file)
    bfile = open(bin_filename, "wb")
    vistrail.binary_data.tofile(bfile)
    bfile.close()
    bin_fname = os.path.join(os.path.dirname(bin_filename), 'data')
    if os.path.exists(bin_fname):
        os.remove(bin_fname)
    os.rename(bin_filename, bin_fname)
    zip_fnames.append(bin_fname)
    
    getBuilderWindow().updateProgress(0.5)

    if vistrail.log is not None and len(vistrail.log.workflow_execs) > 0:
        if vistrail.log_filename is None:
            (log_file, log_filename) = tempfile.mkstemp(suffix='.xml')
            os.close(log_file)
            log_file = open(log_filename, "wb")
        else:
            log_filename = vistrail.log_filename
            log_file = open(log_filename, 'ab')

        print "+++ ", log_filename
        print "*** ", log_file
        if not hasattr(log_file, "write"):
            print "no!!!"
        
        # append log to log_file
        for workflow_exec in vistrail.log.workflow_execs:
            daoList = getVersionDAO(currentVersion)
            daoList.save_to_xml(workflow_exec, log_file, {}, currentVersion)
        log_file.close()

        log_fname = os.path.join(os.path.dirname(log_filename), 'log')
        if os.path.exists(log_fname):
            os.remove(log_fname)
        os.rename(log_filename, log_fname)
        zip_fnames.append(log_fname)

    try:
        zf = zipfile.ZipFile(file=filename,mode='w',
                             allowZip64=True)
        # Add standard vistrails files
        for f in zip_fnames:
            zf.write(f,os.path.basename(f),zipfile.ZIP_DEFLATED)

        if zip_audio_folder[0] != None:
            if os.path.isdir(zip_audio_folder[0]) == True:
                for d in zip_audio_folder:
                    addFolderToZipFile(zf, d, "audio")
        
        if zip_video_folder[0] != None:
            if os.path.isdir(zip_video_folder[0]) == True:
                for v in zip_video_folder:
                    addFolderToZipFile(zf, v, "video")
                    

        getBuilderWindow().updateProgress(0.75)
        # Add saved files. Append indicator of file type because it needed
        # when extracting the zip on Windows
        for (f,b) in vistrail.saved_files:
            basename = os.path.join("vt_saves",os.path.basename(f))
            if b:
                basename += ".b"        
            else:
                basename += ".a"
            zf.write(f, basename, zipfile.ZIP_DEFLATED)
        zf.close()
        
        currentFolder = []
        
    except Exception, e:
        # Allow autosaves to fail silently
        if filename.find('vt_autosaves') <0:
            raise Exception('Error writing file!\nThe file may be invalid or you\nmay have insufficient permissions.')