Exemplo n.º 1
0
    def thread_do(self):
        self.response = urllib.request.urlopen(self.uri)

        def url_name(url):
            return os.path.basename(url.rstrip("/"))

        def header_name(headers):
            content_disp = headers.get("Content-Disposition", "")
            for part in content_disp.split(";"):
                if part.strip().lower().startswith("filename="):
                    return part.split("=", 1)[-1]
            return content_disp

        destname = (header_name(self.response.headers)
                    or url_name(self.response.url))

        if self.use_tempfile:
            (self.destfile, self.destpath) = utils.get_safe_tempfile()
        else:
            (self.destfile, self.destpath) = \
                utils.get_destfile_in_directory(self.destdir, destname)
        try:
            if not self.destfile:
                raise IOError("Could not write output file")

            shutil.copyfileobj(self.response, self.destfile)
        finally:
            self.destfile.close()
            self.response.close()
Exemplo n.º 2
0
    def thread_do(self):
        self.response = urllib.request.urlopen(self.uri)

        def url_name(url):
            return os.path.basename(url.rstrip("/"))
        def header_name(headers):
            content_disp = headers.get("Content-Disposition", "")
            for part in content_disp.split(";"):
                if part.strip().lower().startswith("filename="):
                    return part.split("=", 1)[-1]
            return content_disp

        destname = (header_name(self.response.headers) or
                    url_name(self.response.url))

        if self.use_tempfile:
            (self.destfile, self.destpath) = utils.get_safe_tempfile()
        else:
            (self.destfile, self.destpath) = \
                utils.get_destfile_in_directory(self.destdir, destname)
        try:
            if not self.destfile:
                raise IOError("Could not write output file")

            shutil.copyfileobj(self.response, self.destfile)
        finally:
            self.destfile.close()
            self.response.close()
Exemplo n.º 3
0
 def activate(self, leaf, iobj):
     outfile, outpath = utils.get_destfile_in_directory(iobj.object, _("Empty File"))
     try:
         l_text = kupferstring.tolocale(leaf.object)
         outfile.write(l_text)
         if not l_text.endswith("\n"):
             outfile.write("\n")
     finally:
         outfile.close()
     return FileLeaf(outpath)
Exemplo n.º 4
0
 def activate(self, leaf, iobj):
     outfile, outpath = \
             utils.get_destfile_in_directory(iobj.object, _("Empty File"))
     try:
         l_text = kupferstring.tolocale(leaf.object)
         outfile.write(l_text)
         if not l_text.endswith(b"\n"):
             outfile.write(b"\n")
     finally:
         outfile.close()
     return FileLeaf(outpath)
Exemplo n.º 5
0
 def activate(self, leaf, iobj):
     if iobj.object:
         # Copy the template to destination directory
         basename = os.path.basename(iobj.object)
         tmpl_gfile = gio.File(iobj.object)
         destpath = utils.get_destpath_in_directory(leaf.object, basename)
         destfile = gio.File(destpath)
         tmpl_gfile.copy(destfile, flags=gio.FILE_COPY_ALL_METADATA)
     else:
         # create new empty file
         filename = unicode(iobj)
         f, destpath = utils.get_destfile_in_directory(leaf.object, filename)
         f.close()
     return FileLeaf(destpath)
Exemplo n.º 6
0
	def activate(self, leaf, iobj):
		if iobj.object is not None:
			# Copy the template to destination directory
			basename = os.path.basename(iobj.object)
			tmpl_gfile = gio.File(iobj.object)
			destpath = utils.get_destpath_in_directory(leaf.object, basename)
			destfile = gio.File(destpath)
			tmpl_gfile.copy(destfile, flags=gio.FILE_COPY_ALL_METADATA)
		elif isinstance(iobj, NewFolder):
			filename = unicode(iobj)
			destpath = utils.get_destpath_in_directory(leaf.object, filename)
			os.makedirs(destpath)
		else:
			# create new empty file
			filename = unicode(iobj)
			f, destpath = utils.get_destfile_in_directory(leaf.object, filename)
			f.close()
		return FileLeaf(destpath)
Exemplo n.º 7
0
 def activate(self, leaf, iobj):
     if iobj.object is not None:
         # Copy the template to destination directory
         basename = os.path.basename(iobj.object)
         tmpl_gfile = Gio.File.new_for_path(iobj.object)
         destpath = utils.get_destpath_in_directory(leaf.object, basename)
         destfile = Gio.File.new_for_path(destpath)
         tmpl_gfile.copy(destfile, Gio.FileCopyFlags.ALL_METADATA, None, None, None)
     elif isinstance(iobj, NewFolder):
         filename = str(iobj)
         destpath = utils.get_destpath_in_directory(leaf.object, filename)
         os.makedirs(destpath)
     else:
         # create new empty file
         filename = str(iobj)
         f, destpath = utils.get_destfile_in_directory(leaf.object, filename)
         f.close()
     return FileLeaf(destpath)