Save the GADDAG to file.

        Args:
            path: path to save the GADDAG to.
            compressed: compress the saved GADDAG using gzip.
            exist_ok: overwrite existing file at `path`.
776189
def save(self, path, compressed=True, exist_ok=False):
        
        path = os.path.expandvars(os.path.expanduser(path))
        if os.path.isfile(path) and not exist_ok:
            raise OSError(17, os.strerror(17), path)

        if os.path.isdir(path):
            path = os.path.join(path, "out.gdg")

        if compressed:
            bytes_written = cgaddag.gdg_save_compressed(self.gdg, path.encode("ascii"))
        else:
            bytes_written = cgaddag.gdg_save(self.gdg, path.encode("ascii"))

        if bytes_written == -1:
            errno = ctypes.c_int.in_dll(ctypes.pythonapi, "errno").value
            raise OSError(errno, os.strerror(errno), path)

        return bytes_written
688441
def compress_to(self, archive_path=None):
        
        if archive_path is None:
            archive = tempfile.NamedTemporaryFile(delete=False)
            tar_args = ()
            tar_kwargs = {'fileobj': archive}
            _return = archive.name
        else:
            tar_args = (archive_path)
            tar_kwargs = {}
            _return = archive_path
        tar_kwargs.update({'mode': 'w:gz'})
        with closing(tarfile.open(*tar_args, **tar_kwargs)) as tar:
            tar.add(self.path, arcname=self.file)

        return _return
635157
def save_to(path, options = {})
      options[:quotes] ||= %w({ })

      File.open(path, 'w:UTF-8') do |f|
        f.write(to_s(options))
      end

      self
    end
921874
def save(self, path):
        

        path_dir = os.path.split(path)[0]
        if not os.path.exists(path_dir):
            try:
                os.makedirs(path_dir)
            except OSError:
                pass

        with open(path, 'wb') as out:
            out.write(self._bytes_body if self._bytes_body is not None
                      else b'')
1312843
def to_file(self, path):
        
        with open(os.path.expanduser(path), "w") as ofile:
            ofile.write(self.__repr__())
665254
def _copy_file(self, path):
        
        full_path = self.get_full_archive_path(path)
        # Try to make the dir, eat exception if it fails
        try:
            os.makedirs(os.path.dirname(full_path))
        except OSError:
            pass
        logger.debug("Copying %s to %s", path, full_path)
        shutil.copyfile(path, full_path)
        return path
608559
def save_to_file(self, path):
        

        with open(path, 'w') as out:
            out.write(json.dumps(self.get_dict()))
383880
def is_compressed(path):
        
        if path.endswith(".zip"):
            return "zip"
        elif path.endswith(".tar.gz"):
            return "tar.gz"
        elif path.endswith(".tar.bz2"):
            return "tar.bz2"
        elif path.endswith(".gz"):
            return "gz"
        elif path.endswith(".bz2"):
            return "bz2"
        elif path.endswith(".tar"):
            return "tar"
        return ""
81406
def render_to(path, options={})
      overwrite = options[:overwrite] == true || true
      compress  = options[:gzip]      == true || false

      path = File.expand_path(path)
      path << ".gz" unless path =~ /\.gz\z/i if compress

      if File.exists?(path) && !overwrite
        raise RuntimeError, "File already exists and not overwritable!"
      end

      File.open(path, 'wb') do |f|
        unless compress
          f.write(self.render)
        else
          gz = Zlib::GzipWriter.new(f)
          gz.write(self.render)
          gz.close
        end
      end
    end
1214763
def create_gzip_file(filepath, overwrite):
    '''
    '''
    compressed_path = filepath + '.gz'

    with open(filepath, 'rb') as uncompressed:
        gzip_compress_obj = zlib.compressobj(COMPRESSION_LEVEL,
                                                zlib.DEFLATED, WBITS)

        uncompressed_data = uncompressed.read()
        gzipped_data = gzip_compress_obj.compress(uncompressed_data)
        gzipped_data += gzip_compress_obj.flush()

        if len(gzipped_data) >= len(uncompressed_data):
            logger.debug('No improvement: %s' % filepath)
            return

        with open(compressed_path, 'wb') as compressed:
            logger.debug('Compressing: %s' % filepath)
            try:
                compressed.write(gzipped_data)
            except Exception as ex:
                logger.critical('Gzip compression failed: %s' % ex)

        if overwrite:
            logger.debug('Overwriting: %s with %s' % (filepath, compressed_path))
            os.remove(filepath)
            os.rename(compressed_path, filepath)
266964
def save_checksum(self, path):
        
        checksum = file_hash(path)
        kv = unitdata.kv()
        kv.set('hardening:%s' % path, checksum)
        kv.flush()
811492
def load(self, path):
        
        path = os.path.expandvars(os.path.expanduser(path))

        gdg = cgaddag.gdg_load(path.encode("ascii"))
        if not gdg:
            errno = ctypes.c_int.in_dll(ctypes.pythonapi, "errno").value
            raise OSError(errno, os.strerror(errno), path)

        self.__del__()
        self.gdg = gdg.contents
648076
def save(self, path, binary=False):
        
        if binary:
            ret = lib.EnvBsave(self._env, path.encode())
        else:
            ret = lib.EnvSave(self._env, path.encode())
        if ret == 0:
            raise CLIPSError(self._env)
353333
def add_file(self, path, compress):
        
        if not os.path.isfile(path):
            raise ValueError('{} is not a file'.format(path))
        self.fileobj.seek(self.last_offset)

        with open(path, 'rb') as f:
            flags = os.stat(path).st_mode & 0o777
            self.add_fileobj(f, path, compress, flags)
1215690
def save(self, content):
        
        # backup existing file if needed
        if os.path.exists(self.file_path) and not self.assume_yes:
            message = "Overwrite existing {}? (y/n) "
            if not confirm(message.format(self.filename)):
                self.backup()

        # write file
        self.output("Saving " + self.filename)
        with open(self.file_path, "wb") as handler:
            if not isinstance(content, bytes):
                content = bytes(content, "utf-8")
            handler.write(content)
        self.yeah("Done!")
1008869
def compress(self, image_path):
    ''''''
    if os.path.exists(image_path):
        compressed_image = "%s.gz" %image_path
        os.system('gzip -c -6 %s > %s' %(image_path, compressed_image))
        return compressed_image

    bot.exit("Cannot find image %s" %image_path)
531622
def save(self, path, **kwargs):
        
        self.plot if not hasattr(self, '_plot') else None
        self.figure.savefig(path, **kwargs)