[sugar] [PATCH] Browse - copy Image to clipboard under rainbow

Simon Schampijer simon
Mon Jun 9 11:11:39 EDT 2008


Tomeu Vizoso wrote:
> On Sun, Jun 8, 2008 at 11:44 AM, Simon Schampijer <simon at schampijer.de> wrote:
>> Hi,
>>
>> tomeu can you verify that patch?
>>
>> Use case: Copying an image using the palette under rainbow.
>>
>> We loose the data which exist in the filename, should we try to store this
>> somehow?
> 
> Hi,
> 
> good catches, what about:
> 
> -        file_name = urlparse.urlparse(self._url).path
> -        extension = None
> +        file_name = os.path.basename(urlparse.urlparse(self._url).path)
>          if '.' in file_name:
> -            extension = file_name.split('.')[1]
> -        fd, self._temp_file = tempfile.mkstemp(suffix='.' + extension)
> +            base_name, extension = file_name.split('.')
> +            extension = '.' + extension
> +        else:
> +            base_name = file_name
> +            extension = ''
> +
> +        temp_path = os.path.join(activity.get_activity_root(), 'instance')
> +        fd, self._temp_file = tempfile.mkstemp(dir=temp_path, prefix=base_name,
> +                                               suffix=extension)
>          os.close(fd)
> +        os.chmod(self._temp_file, 0644)
> 
> This way we specify the dir we want to save to, preserve the base file
> name, and make sure it's unique by using mkstemp.
> 
> Thanks,
> 
> Tomeu
> 

Yes - this is great! Pushed to git master and tested on the xo as working.

Simon



More information about the Sugar-devel mailing list