示例#1
0
    def test_toy_app(self):
        a = Application()
        a.finder.find()
        a.get()
        s = pickle.dumps(a)
        b = pickle.loads(s)

        with self.assertRaisesRegex(
                AttributeError,
                "'StringFinder' object has no attribute 'data'"):
            b.get()

        # Works fine.
        c = VersionedUnpickler(io.BytesIO(s)).load()
        c.get()
示例#2
0
def load_project(pickle_filename, updater_path, application_version, protocol,
                                                                  max_pass=-1):
    """ Reads a project from a pickle file and if necessary will update it to
    the latest version of the application.
    """

    latest_file = pickle_filename

    # Read the pickled project's metadata.
    f = open(latest_file, 'rb')
    metadata = VersionedUnpickler(f).load(max_pass)
    f.close()
    project_version = metadata.get('version', False)

    if not project_version:
        raise ValueError, "Could not read version number from the project file"

    logger.debug('Project version: %d, Application version: %d' %
                (project_version, application_version))

    # here you can temporarily force an upgrade each time for testing ....
    # project_version = 0
    latest_file = upgrade_project(pickle_filename, updater_path,
                                project_version, application_version, protocol,
                                max_pass)

    # Finally we can import the project ...
    logger.info('loading %s' % latest_file)
    i_f = open(latest_file, 'rb')
    version = VersionedUnpickler(i_f).load(max_pass)
    project = VersionedUnpickler(i_f).load(max_pass)
    i_f.close()

    return project
def load_project(pickle_filename, updater_path, application_version, protocol,
                                                                  max_pass=-1):
    """ Reads a project from a pickle file and if necessary will update it to
    the latest version of the application.
    """

    latest_file = pickle_filename

    # Read the pickled project's metadata.
    f = open(latest_file, 'rb')
    metadata = VersionedUnpickler(f).load(max_pass)
    f.close()
    project_version = metadata.get('version', False)

    if not project_version:
        raise ValueError("Could not read version number from the project file")

    logger.debug('Project version: %d, Application version: %d' %
                (project_version, application_version))

    # here you can temporarily force an upgrade each time for testing ....
    # project_version = 0
    latest_file = upgrade_project(pickle_filename, updater_path,
                                project_version, application_version, protocol,
                                max_pass)

    # Finally we can import the project ...
    logger.info('loading %s' % latest_file)
    i_f = open(latest_file, 'rb')
    version = VersionedUnpickler(i_f).load(max_pass)
    project = VersionedUnpickler(i_f).load(max_pass)
    i_f.close()

    return project