Beispiel #1
0
    def __init__(self, filename, properties=None):
        """Initialize the file that contains the properties. If the file does
        not exist it is assumed that the set of properties is not None. If the
        file exists the properties dictionary is used as a set of defaults.

        Parameters
        ----------
        filename: string
            Name of the file storing the object properties
        properties: dict, optional
            Initial set of default properties.
        """
        self.filename = os.path.abspath(filename)
        # Create the file from the given set of properties if it does not exist.
        if not os.path.isfile(self.filename):
            if properties is None:
                raise ValueError('missing default properties')
            self.properties = dict(properties)
            with open(self.filename, 'w') as f:
                #yaml.dump(self.properties, f, default_flow_style=False, Dumper=CDumper)
                dump_json(self.properties, f)
        elif not properties is None:
            self.properties = dict(properties)
        else:
            self.properties = dict()
Beispiel #2
0
 def to_file(self):
     """Write the current state of the viztrail to file. Sets the last
     modified at timestamp to the current time.
     """
     self.last_modified_at = get_current_time()
     # Serialize viztrail
     doc = {
         'id':
         self.identifier,
         'env':
         self.exec_env.identifier,
         'branches': [{
             'id':
             b,
             'versions': [w.to_dict() for w in self.branches[b].workflows]
         } for b in self.branches],
         'timestamps': {
             'createdAt': self.created_at.isoformat(),
             'lastModifiedAt': self.last_modified_at.isoformat()
         },
         'versionCounter':
         self.version_counter.value,
         'moduleCounter':
         self.module_counter.value
     }
     # Write viztrail serialization to file
     with open(os.path.join(self.fs_dir, VIZTRAIL_FILE), 'w') as f:
         #yaml.dump(doc, f, default_flow_style=False, Dumper=CDumper)
         dump_json(doc, f)
Beispiel #3
0
    def write_index(self, files):
        """Write content of the file index.

        Parameters
        -------
        files: dict
            New context for file index
        """
        content = {'files': [fh.to_dict() for fh in files.values()]}
        with open(self.index_file, 'w') as f:
            #yaml.dump(content, f, default_flow_style=False, Dumper=CDumper)
            dump_json(content, f)
Beispiel #4
0
    def to_file(self, filename):
        """Write dataset to file. The default serialization format is Json.

        Parameters
        ----------
        filename: string
            Name of the file to write
        """
        doc = {
            'id': self.identifier,
            'columns': [col.to_dict() for col in self.columns],
            'tableName': str(self.table_name),
            'rowCounter': self.row_counter
        }
        with open(filename, 'w') as f:
            dump_json(doc, f)
Beispiel #5
0
    def to_file(self, filename):
        """Write dataset to file. The default serialization format is Yaml.

        Parameters
        ----------
        filename: string
            Name of the file to write
        """
        doc = {
            'id': self.identifier,
            'columns': [col.to_dict() for col in self.columns],
            'rowIdColumn': self.rowid_column.to_dict(),
            'rows': self.row_ids,
            'tableName': str(self.table_name),
            'columnCounter': self.column_counter,
            'rowCounter': self.row_counter
        }
        with open(filename, 'w') as f:
            #yaml.dump(doc, f, default_flow_style=False, Dumper=CDumper)
            dump_json(doc, f)
Beispiel #6
0
    def to_file(file_name, source_branch, workflow_version, module_id):
        """Write provenance information to file.

        Parameters
        ----------
        source_branch : string
            Unique branch identifier of source branch
        workflow_version: int
            Version number of source workflow.
        module_id: int
            Identifier of module at which the new branch started
        """
        doc = {
            'branch': source_branch,
            'workflow': workflow_version,
            'module': module_id
        }
        with open(file_name, 'w') as f:
            #yaml.dump(doc, f, default_flow_style=False, Dumper=CDumper)
            dump_json(doc, f)
Beispiel #7
0
    def write_workflow(self, exec_result):
        """Write workflow execution result into a new workflow file.

        Parameters
        ----------
        exec_result: vizier.workflow.engine.base.WorkflowExecutionResult
            Resulting workflow state after execution

        Returns
        -------
        datetime.datetime
        """
        # Create dictionary for workflow information
        created_at = get_current_time()
        doc = {
            'version': exec_result.version,
            'createdAt': created_at.isoformat(),
            'modules': [m.to_dict() for m in exec_result.modules]
        }
        # Write handle to file
        with open(workflow_file(self.fs_dir, exec_result.version), 'w') as f:
            #yaml.dump(doc, f, default_flow_style=False, Dumper=CDumper)
            dump_json(doc, f)
        return created_at