code: def write_profile(self, profile_directory, relations_filename=None,
                        key_filter=True,
                        append=False, gzip=None):
          
          if relations_filename:
              src_rels = os.path.abspath(relations_filename)
              relations = get_relations(relations_filename)
          else:
              src_rels = os.path.abspath(os.path.join(self.root,
                                                      _relations_filename))
              relations = self.relations
  
          tgt_rels = os.path.abspath(os.path.join(profile_directory,
                                                  _relations_filename))
          if not (os.path.isfile(tgt_rels) and src_rels == tgt_rels):
              with open(tgt_rels, 'w') as rel_fh:
                  print(open(src_rels).read(), file=rel_fh)
  
          tables = self._tables
          if tables is not None:
              tables = set(tables)
          for table, fields in relations.items():
              if tables is not None and table not in tables:
                  continue
              try:
                  fn = _table_filename(os.path.join(self.root, table))
                  _gzip = gzip if gzip is not None else fn.endswith('.gz')
                  rows = list(self.read_table(table, key_filter=key_filter))
                  _write_table(
                      profile_directory, table, rows, fields,
                      append=append, gzip=_gzip, encoding=self.encoding
                  )
              except ItsdbError:
                  logging.warning(
                      'Could not write "{}"; table doesn\'t exist.'.format(table)
                  )
                  continue
  
          self._cleanup(gzip=gzip)
docs: Write all tables (as specified by the relations) to a profile.
  
          Args:
              profile_directory: The directory of the output profile
              relations_filename: If given, read and use the relations
                  at this path instead of the current profile's
                  relations
              key_filter: If True, filter the rows by keys in the index
              append: If `True`, append profile data to existing tables
                  in the output profile directory
              gzip: If `True`, compress tables using `gzip`. Table
                  filenames will have `.gz` appended. If `False`, only
                  write out text files. If `None`, use whatever the
                  original file was.