src/pds_doi_service/core/db/transaction_on_disk.py
def write(self, transaction_dir, input_ref=None, output_content=None, output_content_type=None):
        """
        Write the input and output products from a transaction to disk.
        All directories and files created will have both user and group
        read/write permissions set accordingly.

        Parameters
        ----------
        transaction_dir : str
            Location on disk to commit the transaction input and output files.
            This method creates the directory if it does not already exist and
            ensures group read/write permission bits are set.
        input_ref : str, optional
            Path to the input file or directory to associate with the transaction.
            Determines the input file(s) copied to the transaction history.
        output_content : str, optional
            The output label content to associate to with the transaction.
            Determines the contents of the output file copied to the transaction history.
        output_content_type : str, optional
            The content type of output_content. Should be one of "xml" or "json".

        """

        # Set up the appropriate umask in-case os.makedirs needs to create any
        # intermediate parent directories (its mask arg only affects the created leaf directory)
        prev_umask = os.umask(0o0002)

        # Create the new transaction history directory with group-rw enabled
        os.makedirs(transaction_dir, exist_ok=True, mode=0o0775)

        if input_ref:
            if os.path.isdir(input_ref):
                # Copy the input files, but do not preserve their permissions so
                # the umask we set above takes precedence
                copy_tree(input_ref, os.path.join(transaction_dir, "input"), preserve_mode=False)
            else:
                input_content_type = os.path.splitext(input_ref)[-1]

                # Write input file with provided content.
                # Note that the file name is always 'input' plus the extension based
                # on the content_type (input.xml or input.csv or input.xlsx)
                full_input_name = os.path.join(transaction_dir, "input" + input_content_type)

                if os.path.isfile(input_ref):
                    shutil.copy2(input_ref, full_input_name)
                else:  # remote resource
                    r = requests.get(input_ref, allow_redirects=True)

                    with open(full_input_name, "wb") as outfile:
                        outfile.write(r.content)

                    r.close()

                # Set up permissions for copied input
                os.chmod(full_input_name, 0o0664)

        # Write output file with provided content
        # The extension of the file is determined by the provided content type
        if output_content and output_content_type:
            full_output_name = os.path.join(transaction_dir, ".".join(["output", output_content_type]))

            with open(full_output_name, "w") as outfile:
                outfile.write(output_content)

            # Set up permissions for copied output
            os.chmod(full_output_name, 0o0664)

        logger.info(f"Transaction files saved to {transaction_dir}")

        # Restore the previous umask
        os.umask(prev_umask)

        Write the input and output products from a transaction to disk.
        All directories and files created will have both user and group
        read/write permissions set accordingly.

        Parameters
        ----------
        transaction_dir : str
            Location on disk to commit the transaction input and output files.
            This method creates the directory if it does not already exist and
            ensures group read/write permission bits are set.
        input_ref : str, optional
            Path to the input file or directory to associate with the transaction.
            Determines the input file(s) copied to the transaction history.
        output_content : str, optional
            The output label content to associate to with the transaction.
            Determines the contents of the output file copied to the transaction history.
        output_content_type : str, optional
            The content type of output_content. Should be one of "xml" or "json".

        
Write the input and output products from a transaction to disk.
All directories and files created will have both user and group
read/write permissions set accordingly.

Parameters

transaction_dir : str
Location on disk to commit the transaction input and output files.
This method creates the directory if it does not already exist and
ensures group read/write permission bits are set.
input_ref : str, optional
Path to the input file or directory to associate with the transaction.
Determines the input file(s) copied to the transaction history.
output_content : str, optional
The output label content to associate to with the transaction.
Determines the contents of the output file copied to the transaction history.
output_content_type : str, optional
The content type of output_content. Should be one of "xml" or "json".
Write the input and output products from a transaction to disk . All directories and files created will have both user and group read / write permissions set accordingly . Parameters transaction_dir : str Location on disk to commit the transaction input and output files . This method creates the directory if it does not already exist and ensures group read / write permission bits are set . input_ref : str optional Path to the input file or directory to associate with the transaction . Determines the input file ( s ) copied to the transaction history . output_content : str optional The output label content to associate to with the transaction . Determines the contents of the output file copied to the transaction history . output_content_type : str optional The content type of output_content . Should be one of " xml " or " json " .
def write(self, transaction_dir, input_ref=None, output_content=None, output_content_type=None):
        prev_umask = os.umask(0o0002)
        os.makedirs(transaction_dir, exist_ok=True, mode=0o0775)
        if input_ref:
            if os.path.isdir(input_ref):
                copy_tree(input_ref, os.path.join(transaction_dir, "input"), preserve_mode=False)
            else:
                input_content_type = os.path.splitext(input_ref)[-1]
                full_input_name = os.path.join(transaction_dir, "input" + input_content_type)
                if os.path.isfile(input_ref):
                    shutil.copy2(input_ref, full_input_name)
                else:  
                    r = requests.get(input_ref, allow_redirects=True)
                    with open(full_input_name, "wb") as outfile:
                        outfile.write(r.content)
                    r.close()
                os.chmod(full_input_name, 0o0664)
        if output_content and output_content_type:
            full_output_name = os.path.join(transaction_dir, ".".join(["output", output_content_type]))
            with open(full_output_name, "w") as outfile:
                outfile.write(output_content)
            os.chmod(full_output_name, 0o0664)
        logger.info(f"Transaction files saved to {transaction_dir}")
        os.umask(prev_umask)
def write ( self , transaction_dir , input_ref = None , output_content = None , output_content_type = None ) : prev_umask = os . umask ( 0o0002 ) os . makedirs ( transaction_dir , exist_ok = True , mode = 0o0775 ) if input_ref : if os . path . isdir ( input_ref ) : copy_tree ( input_ref , os . path . join ( transaction_dir , "input" ) , preserve_mode = False ) else : input_content_type = os . path . splitext ( input_ref ) [ - 1 ] full_input_name = os . path . join ( transaction_dir , "input" + input_content_type ) if os . path . isfile ( input_ref ) : shutil . copy2 ( input_ref , full_input_name ) else : r = requests . get ( input_ref , allow_redirects = True ) with open ( full_input_name , "wb" ) as outfile : outfile . write ( r . content ) r . close ( ) os . chmod ( full_input_name , 0o0664 ) if output_content and output_content_type : full_output_name = os . path . join ( transaction_dir , "." . join ( [ "output" , output_content_type ] ) ) with open ( full_output_name , "w" ) as outfile : outfile . write ( output_content ) os . chmod ( full_output_name , 0o0664 ) logger . info ( f"Transaction files saved to {transaction_dir}" ) os . umask ( prev_umask )
Write the input and output products from a transaction to disk.
Write the input and output products from a transaction to disk .
"""
        Write the input and output products from a transaction to disk.
        All directories and files created will have both user and group
        read/write permissions set accordingly.

        Parameters
        ----------
        transaction_dir : str
            Location on disk to commit the transaction input and output files.
            This method creates the directory if it does not already exist and
            ensures group read/write permission bits are set.
        input_ref : str, optional
            Path to the input file or directory to associate with the transaction.
            Determines the input file(s) copied to the transaction history.
        output_content : str, optional
            The output label content to associate to with the transaction.
            Determines the contents of the output file copied to the transaction history.
        output_content_type : str, optional
            The content type of output_content. Should be one of "xml" or "json".

        """ # Set up the appropriate umask in-case os.makedirs needs to create any # intermediate parent directories (its mask arg only affects the created leaf directory) # Create the new transaction history directory with group-rw enabled # Copy the input files, but do not preserve their permissions so # the umask we set above takes precedence # Write input file with provided content. # Note that the file name is always 'input' plus the extension based # on the content_type (input.xml or input.csv or input.xlsx) # remote resource # Set up permissions for copied input # Write output file with provided content # The extension of the file is determined by the provided content type # Set up permissions for copied output # Restore the previous umask
self
transaction_dir
input_ref
output_content
output_content_type