Example #1
0
 def _create_namespace_files(self, object_type: str) -> typing.NoReturn:
     """Generate the schema files for the given object type"""
     LOGGER.info('Creating %s files', object_type.lower())
     formatter = getattr(self.structure,
                         object_type.lower().replace(' ', '_'),
                         self.structure.generic)
     namespace = {}
     for entry in _filter(self.dump.entries, object_type):
         self._mark_processed(entry.dump_id)
         if entry.namespace not in namespace.keys():
             namespace[entry.namespace] = []
         data = formatter(entry)
         data = self._remove_empty_values(data)
         namespace[entry.namespace].append(data)
     for value in namespace.keys():
         key = '{}S'.format(object_type)
         file_path = constants.PATHS[object_type] / '{}.{}'.format(
             value, YAML_EXTENSION)
         if str(file_path) in self.ignore:
             LOGGER.debug('Skipping %s', file_path)
             continue
         self.files_created.append(
             storage.save(self.project_path, file_path, key, value, {
                 'schema': value,
                 key.lower(): namespace[value]
             }))
Example #2
0
 def _create_user_files(self) -> typing.NoReturn:
     """Generate the role files based upon the collected information"""
     LOGGER.info('Creating user files')
     for role in [
             r for r in self._roles.values()
             if r.get('password') or r['type'] == constants.USER
     ]:
         data = {
             'name': role['role'],
             'password': role['password'],
             'grants': {
                 '{}s'.format(k.lower()): v
                 for k, v in role['grant'].items() if v
             },
             'revocations': {
                 '{}s'.format(k.lower()): v
                 for k, v in role['revoke'].items() if v
             },
             'options': role.get('options'),
             'settings': role.get('settings')
         }
         self.files_created.append(
             storage.save(
                 self.project_path, constants.PATHS[constants.USER] /
                 '{}.{}'.format(role['role'], YAML_EXTENSION),
                 constants.USER, role['role'], data))
Example #3
0
 def _create_group_files(self) -> typing.NoReturn:
     """Generate the group files based upon the collected information"""
     LOGGER.info('Creating group files')
     for role in [
             r for r in self._roles.values() if r['type'] == constants.GROUP
     ]:
         data = {
             'name': role['role'],
             'grants': {
                 '{}s'.format(k.lower()): v
                 for k, v in role['grant'].items() if v
             },
             'revocations': {
                 '{}s'.format(k.lower()): v
                 for k, v in role['revoke'].items() if v
             },
             'options': role.get('options'),
             'settings': role.get('settings')
         }
         file_path = constants.PATHS[constants.GROUP] / '{}.{}'.format(
             role['role'], YAML_EXTENSION)
         if str(file_path) in self.ignore:
             LOGGER.debug('Skipping %s', file_path)
             continue
         self.files_created.append(
             storage.save(self.project_path, file_path, constants.GROUP,
                          role['role'], data))
Example #4
0
 def _create_project_file(self) -> typing.NoReturn:
     """Generates project.yaml"""
     LOGGER.debug('Creating the project file (project.yaml)')
     temp = [e for e in self.dump.entries if e.desc == constants.DATABASE]
     self._mark_processed(temp[0].dump_id)
     comments = {
         'pg_dump version': self.dump.dump_version,
         'postgres version': self.dump.server_version,
         'dumped at': arrow.get(self.dump.timestamp).format(ISO_FORMAT)
     }
     project = {'name': self.dump.dbname}
     for entry in self.dump.entries:
         if entry.defn.startswith('SET '):
             self._mark_processed(entry.dump_id)
             match = SET_PATTERN.match(entry.defn)
             project[entry.tag.lower()] = match.group(1)
     project.update({
         'extensions': self._find_extensions(),
         'languages': self._find_languages(),
         'shell_types': self._find_shell_types()
     })
     project = _remove_null_values(project)
     self.files_created.append(
         storage.save(self.project_path, 'project.yaml', constants.DATABASE,
                      self.dump.dbname, project, comments))
Example #5
0
 def _create_schema_files(self) -> typing.NoReturn:
     """Generate the schema files for the given object type"""
     LOGGER.info('Creating schemata files')
     for entry in _filter(self.dump.entries, constants.SCHEMA):
         self._mark_processed(entry.dump_id)
         data = self.structure.schema(entry)
         data = self._remove_empty_values(data)
         self.files_created.append(
             storage.save(
                 self.project_path, constants.PATHS[constants.SCHEMA] /
                 '{}.{}'.format(entry.tag, YAML_EXTENSION), entry.desc,
                 entry.tag, data))
Example #6
0
 def _create_files(self, object_type: str) -> typing.NoReturn:
     """Generate the schema files for the given object type"""
     LOGGER.info('Creating %s files', object_type.lower())
     formatter = getattr(self.structure,
                         object_type.lower().replace(' ', '_'),
                         self.structure.generic)
     for entry in _filter(self.dump.entries, object_type):
         self._mark_processed(entry.dump_id)
         data = formatter(entry)
         data = self._remove_empty_values(data)
         filename = None
         if entry.desc in _FILENAME_MAP:
             filename = _FILENAME_MAP[entry.desc](entry.tag,
                                                  self.files_created)
         file_path = self._object_path(entry, filename)
         if str(file_path) in self.ignore:
             LOGGER.debug('Skipping %s', file_path)
             continue
         self.files_created.append(
             storage.save(self.project_path, file_path, entry.desc,
                          entry.tag, data))
Example #7
0
 def _create_operator_files(self) -> typing.NoReturn:
     """Generate the schema files for operators"""
     LOGGER.info('Creating operator files')
     namespace = {}
     for obj_type in {constants.OPERATOR, constants.OPERATOR_CLASS}:
         for entry in _filter(self.dump.entries, obj_type):
             self._mark_processed(entry.dump_id)
             if entry.namespace not in namespace.keys():
                 namespace[entry.namespace] = []
             data = self.structure.operator(entry)
             data = self._remove_empty_values(data)
             namespace[entry.namespace].append(data)
         for value in namespace.keys():
             for offset, row in namespace[value]:
                 if 'schema' in row.keys():
                     del namespace[value][offset]['schema']
             self.files_created.append(
                 storage.save(
                     self.project_path,
                     constants.PATHS[constants.OPERATOR] /
                     '{}.{}'.format(value, YAML_EXTENSION),
                     '{}S'.format(constants.OPERATOR), value,
                     {'operators': namespace[value]}))