Download attachments, update @ok

 === Return
 true:: Always return true
768533
def download_attachments
      unless @scripts.all? { |s| s.attachments.empty? }
        @audit.create_new_section('Downloading attachments')
        audit_time do
          @scripts.each do |script|
            attach_dir = @right_scripts_cookbook.cache_dir(script)
            script.attachments.each do |a|
              script_file_path = File.join(attach_dir, a.file_name)
              @audit.update_status("Downloading #{a.file_name} into #{script_file_path} through Repose")
              begin
                attachment_dir = File.dirname(script_file_path)
                FileUtils.mkdir_p(attachment_dir)
                tempfile = Tempfile.open('attachment', attachment_dir)
                tempfile.binmode
                @downloader.download(a.url) do |response|
                  tempfile << response
                end
                File.unlink(script_file_path) if File.exists?(script_file_path)
                File.link(tempfile.path, script_file_path)
                tempfile.close!
                @audit.append_info(@downloader.details)
              rescue Exception => e
                tempfile.close! unless tempfile.nil?
                @audit.append_info("Repose download failed: #{e.message}.")
                if e.kind_of?(ReposeDownloader::DownloadException) && e.message.include?("Forbidden")
                  @audit.append_info("Often this means the download URL has expired while waiting for inputs to be satisfied.")
                end
                report_failure("Failed to download attachment '#{a.file_name}'", e.message)
              end
            end
          end
        end
      end
      true
    end
3507
def download(self):
        
        if not self.can_update():
            self._tcex.handle_error(910, [self.type])

        return self.tc_requests.download(self.api_type, self.api_sub_type, self.unique_id)
960627
def download(self, force=False):
        
        exists, dest_path = self._downloader.cache.exists_packed(package=self, pkg_path=self.packed_path,
                                                                 check_stat=not self._in_cache)
        unp_exists, unp_path = self._downloader.cache.exists_unpacked(package=self, pkg_path=self.unpacked_path)

        # Если архива нет, то и кешу доверять не стоит
        if not exists:
            unp_exists = False

        if exists and not self.packed_path:
            self.packed_path = dest_path

        if force or not exists:
            # _packed_path = self._packed_path
            dest_path_tmp = dest_path + ".tmp"
            if os.path.exists(dest_path_tmp):
                os.remove(dest_path_tmp)
            self._adapter.download_package(self._pkg, dest_path_tmp)
            os.rename(dest_path_tmp, dest_path)
            self.packed_path = dest_path
            # if not _packed_path:
            self._not_cached = True
        else:
            if unp_exists and not self.unpacked_path:
                self.unpacked_path = unp_path
                self._not_cached = False

        if self._not_cached and unp_exists:
            shutil.rmtree(unp_path, ignore_errors=True)

        return self.packed_path
761263
def download
      return io if io.is_a?(Tempfile)

      Tempfile.new(id, binmode: true).tap do |tempfile|
        IO.copy_stream(io, tempfile)
        tempfile.rewind
        tempfile.fsync
      end
    end
692857
def downloadTo(self, href, localpath):
        
        for iTry in range(TRYINGS):
            logger.info(u("downloadTo(%s): %s %s") % (iTry, href, localpath))
            try:
                href = remote(href)
                localpath = _(localpath)

                conn = self.getConnection()
                conn.request("GET", _encode_utf8(href), "", self.getHeaders())
                response = conn.getresponse()
                checkResponse(response)
                f = None
                try:
                    while True:
                        data = _decode_utf8(response.read(1024))
                        if not data:
                            break
                        if data == u('resource not found'):
                            return False
                        if not f:
                            f = open(localpath, "w")
                        f.write(data)
                finally:
                    if f:
                        f.close()
                return True
            except ConnectionException:
                raise
            except Exception:
                e = sys.exc_info()[1]
                logger.exception(e)
734199
def download(self, to_path=None, name=None, chunk_size='auto',
                 convert_to_pdf=False):
        
        return super().download(to_path=to_path, name=name,
                                chunk_size=chunk_size,
                                convert_to_pdf=convert_to_pdf)
539117
function updateDownloadLink( anchor, objectUrl, fileName ) {
    if ( window.updateDownloadLinkIe11 ) {
        return window.updateDownloadLinkIe11( ...arguments );
    }
    anchor.setAttribute( 'href', objectUrl || '' );
    anchor.setAttribute( 'download', fileName || '' );
}
299226
def download(url, filename, overwrite = False):
	'''  '''

	from requests import get
	from os.path import exists

	debug('Downloading ' + unicode(url) + '...')
	data = get(url)
	if data.status_code == 200:
		if not exists(filename) or overwrite:
			f = open(filename, 'wb')
			f.write(data.content)
			f.close()
		return True
	return False
1354199
def _update_attachments_to_cloud(self):
        
        url = self.build_url(self._endpoints.get('attachments').format(
            id=self._parent.object_id))

        # ! potentially several api requests can be made by this method.

        for attachment in self.__attachments:
            if attachment.on_cloud is False:
                # upload attachment:
                response = self._parent.con.post(url,
                                                 data=attachment.to_api_data())
                if not response:
                    return False

                data = response.json()

                # update attachment data
                attachment.attachment_id = data.get('id')
                attachment.content = data.get(self._cc('contentBytes'), None)
                attachment.on_cloud = True

        for attachment in self.__removed_attachments:
            if attachment.on_cloud and attachment.attachment_id is not None:
                # delete attachment
                url = self.build_url(self._endpoints.get('attachment').format(
                    id=self._parent.object_id, ida=attachment.attachment_id))

                response = self._parent.con.delete(url)
                if not response:
                    return False

        self.__removed_attachments = []  # reset the removed attachments

        log.debug('Successfully updated attachments on {}'.format(
            self._parent.object_id))

        return True
400791
def action_update(self):
        

        order = []
        form = self.request.form
        attachments = form.get("attachments", [])

        for attachment in attachments:
            # attachment is a form mapping, not a dictionary -> convert
            values = dict(attachment)

            uid = values.pop("UID")
            obj = api.get_object_by_uid(uid)

            # delete the attachment if the delete flag is true
            if values.pop("delete", False):
                self.delete_attachment(obj)
                continue

            # remember the order
            order.append(uid)

            # update the attachment with the given data
            obj.update(**values)
            obj.reindexObject()

        # set the attachments order to the annotation storage
        self.set_attachments_order(order)

        # redirect back to the default view
        return self.request.response.redirect(self.context.absolute_url())
1358229
def download(args)
      if args.length != 1
        puts "missing report id for 'download' subcommand"
        return false
      end

      report_id = args[0].to_i
      report    = @common_args.account.reports.find { |r| r.id == report_id }
      if report.nil?
        puts "report '#{report_id}' not found"
        return false
      end

      if report.status != 'Completed'
        puts "cannot download report with status '#{report.status}'"
        return false
      end

      path_name = "test_report.xml"
      puts "Download report #{report.id} in #{path_name}"
      report.download(path_name)
      true
    end
1155018
def download_to_file(uri:, path:)
      uri = Resync::XML.to_uri(uri)
      @helper.fetch_to_file(path: path, uri: uri)
    end
397219
def downloads(params={})
      downloads = get("/orders/#{id}/downloads")
      if downloads
        downloads["downloads"].map { |data| FetchAppAPI::Download.new(data) }
      end
    end
178758
def update(connection=None, urls=None, force_download=False):
    
    db = DbManager(connection)
    db.db_import(urls=urls, force_download=force_download)
    db.session.close()
232452
def update_files paths, matcher, currentVersion, nextVersion
      paths.each do |path|
        update_file path, matcher, currentVersion, nextVersion
      end
    end
1212312
def deliver!(mail)
      check_delivery_params(mail) if respond_to?(:check_delivery_params)

      clean_up

      basepath = File.join(settings[:location], Time.now.to_i.to_s)

      save_email(mail, basepath)

      return true unless mail.attachments.any?

      add_attachments(mail, basepath)
    end
1096150
def file_download(object_id, input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/%s/download' % object_id, input_params, always_retry=always_retry, **kwargs)