Exemplo n.º 1
0
 def sql_handler(destination, filepath):
     try:
         Logger().info('Adding file \'' + filepath + '\'')
         sql_file = ReleaseInstructions._sql_filename(os.path.basename(filepath))
         output_directory = os.path.join(
             destination,
             sql_file.direction.lower(),
             sql_file.ticket_order,
             sql_file.ticket_id,
             sql_file.server,
             sql_file.database
         )
         create_directory(output_directory)
         os.rename(
             filepath,
             os.path.join(
                 output_directory,
                 (
                     sql_file.operation_order + '_' if sql_file.operation_order is not None else ''
                 ) + sql_file.operation + '.sql'
             )
         )
     # pylint: disable=broad-except
     # We are not bothering to handle invalidly named SQL files - these will be
     # ignored from the instruction sent to SysOps.
     # ANY error here and the file gets bounced back to the developer.
     except Exception as exception:
         Logger().error('Failed to handle SQL file \'' + os.path.basename(filepath) + '\'')
         Logger().error('reason: ' +  str(exception))
Exemplo n.º 2
0
 def setup(self, query, fields=None, collate=None, output_path='/tmp'):
     """ Set up the attachments object """
     # pylint: disable=arguments-differ
     self._content = Filter(query, max_results=50, fields=fields)
     self.threadmanager.append(self._content)
     self.projectmanager = Configuration().manager
     self._collate = collate.split(',')
     self._output_path = Replacements().replace(output_path)
     create_directory(self._output_path)
Exemplo n.º 3
0
    def zip_handler(destination, filepath):
        temporary_directory = os.path.join(destination, 'temp')
        create_directory(temporary_directory)
        unzip(filepath, temporary_directory, flatten=True)

        sql_files = [
            filename for filename in os.listdir(
                temporary_directory
            ) if re.search(
                "^.*\.sql$", filename, re.IGNORECASE
            )
        ]
        if len(sql_files) == 0:
            Logger().error('Got zip file but it contains no SQL files. Skipping...')
        for sql in sql_files:
            ReleaseInstructions.sql_handler(destination, os.path.join(temporary_directory, sql))
        shutil.rmtree(temporary_directory)
Exemplo n.º 4
0
    def file_collator(path, attachments):
        """
        This method unpacks all zip files and copies the resulting SQL into a temporary location

        Once complete, it repackages the temporary location and moves it into the Workspace for
        attachment to the release instruction email
        """
        Logger().info('Collating SQL files from attachments')
        package_name = Replacements().replace('mss-platform-release-{FIX_VERSION}').replace('/', '-')
        destination = os.path.join(path, package_name)
        up_dir = os.path.join(destination, 'up')
        down_dir = os.path.join(destination, 'down')
        package_dir = os.path.join(os.getcwd(), 'packages')
        if not os.path.exists(package_dir):
            create_directory(package_dir)

        create_directory(destination)
        create_directory(up_dir)
        create_directory(down_dir)

        for attachment in attachments:
            if hasattr(ReleaseInstructions, attachment.extension.lower() + '_handler'):
                filename = os.path.join(path, attachment.filename)
                Logger().debug(
                    'Calling handler \'' + attachment.extension + '_handler\' for file ' + filename
                )

                try:
                    getattr(ReleaseInstructions, attachment.extension.lower() + '_handler')(
                        destination,
                        os.path.join(path, attachment.filename)
                    )
                except Exception as exception:
                    Logger().error('Failed to add file \'' + filename + '\' to archive')
                    Logger().error('reason: ' + str(exception))

        filename = mkzip(destination, os.path.join(path, package_name + '.zip'))
        shutil.move(os.path.join(destination, filename), os.path.join(package_dir, os.path.basename(filename)))
        return os.path.basename(filename)
Exemplo n.º 5
0
 def test_makedirs_was_never_called(self, mock_makedirs, mock_exists):
     create_directory('/var/lib/git')
     mock_makedirs.assert_not_called()