;
\Hc           @   s   d  Z  d k l Z d k l Z d k Z d k Z d k Td f  d     YZ d   Z	 d e
 e f d	     YZ d
 e f d     YZ d S(   sF   
   Copyright (C) 2005-2006 PimenTech SARL (http://www.pimentech.net)

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  
(   s   DBP(   s   MapN(   s   *s   FileUploadManagerc           B   s    t  Z d  Z d   Z d   Z RS(   s.   
	Copy a Zope uploaded file to a destination
	c         C   s   | |  _  | |  _ | |  _ d S(   st   
		source : Zope FileUpload
		destination_path : file destination path
		destination_name : file destination name
		N(   s   sources   selfs   destination_paths   destination_name(   s   selfs   sources   destination_paths   destination_name(    (    s   file_upload.pys   __init__!   s     		c         C   se   yS |  i i   } t d |  i t i |  i f d  } | i
 |  | i   t SWn t Sn Xd  S(   Ns   %s%s%ss   w(   s   selfs   sources   reads   file_contents   opens   destination_paths   oss   seps   destination_names	   dest_files   writes   closes   Trues   False(   s   selfs   file_contents	   dest_file(    (    s   file_upload.pys   copy+   s    %
(   s   __name__s
   __module__s   __doc__s   __init__s   copy(    (    (    s   file_upload.pys   FileUploadManager   s    	
c         C   s   |  i d d d g j o
 d } nG |  i d d d g j o
 d } n# |  i d d j o
 d	 } n t Sd
 | | f } t |  | |  } | i	   o | Sn t Sd S(   s   
	s   Content-Types
   image/jpegs   image/pjpegs   jpgs	   image/pngs   image/x-pngs   pngs	   image/gifs   gifs   %s.%sN(
   s	   new_images   headerss   file_exts   Falses   names   filenames   FileUploadManagers   destination_paths   fums   copy(   s	   new_images   destination_paths   names   filenames   file_exts   fum(    (    s   file_upload.pys   upload_image6   s     


s   SQLFSStoredImagec           B   sq   t  Z d  Z d Z e d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z RS(   s   
	Store one image
	s   SQLFSStoredImagec
   
      C   sn   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ t	 i
 |  |  i   |	  t |  _ d S(   s   
		path      : where is stored the image
		http_path : path to access image via http
		table     : row describing image is stored this table
		N(   s   paths   selfs	   http_paths   tables	   table_refs   uid_refs   format_images
   type_images   numeros   DBPs   __init__s   getShortNames   connection_ids   Falses   exists(
   s   selfs   paths	   http_paths   tables	   table_refs   uid_refs
   type_images   format_images   numeros   connection_id(    (    s   file_upload.pys   __init__R   s     								c         C   s   |  i   d  S(   N(   s   selfs   updateFromSQL(   s   selfs   ids	   container(    (    s   file_upload.pys   manage_afterAddc   s    c         C   s   d |  i |  i |  i |  i |  i |  i f } |  i |  |  i	 |  } d |  _ d |  _ t |  _ t |  o7 | \ } } } | |  _ | |  _ | |  _ t |  _ n |  i d |  i    d  S(   Nsw   SELECT uid, source, ref_object FROM %s
WHERE %s = %s AND ref_type_image = %s AND ref_format_image = %s AND numero = %s
i    s/   SQLFSStoredImage - image %s - image non trouve(   s   selfs   tables	   table_refs   uid_refs
   type_images   format_images   numeros   querys   messages
   fetchoneofs   ress   uids
   ref_objects   Falses   existss   lens   sources   Trues   getShortName(   s   selfs   uids   ress
   ref_objects   sources   query(    (    s   file_upload.pys   updateFromSQLf   s    .						c         C   s   |  i Sd  S(   N(   s   selfs   exists(   s   self(    (    s   file_upload.pys
   fileExistsx   s    c      
   C   s   |  i   o |  i   n t | |  i |  i    } | o] |  i d |  i	 |  i
 | |  i |  i |  i |  i |  i f  | |  _ d |  _ t |  _ n* |  i d | |  i t i |  i   f  d S(   s7   
		new_image : source image (Zope FileUpload Object)
		s   
			INSERT INTO %s (source, ref_type_image, ref_format_image, numero, %s, ref_object)
			VALUES ('%s', '%s', '%s', '%s', '%s', %s);
			i    s?   SQLFSStoredImage.uploadFromFile - Failed uploading %s to %s%s%sN(   s   selfs
   fileExistss   removes   upload_images	   new_images   paths   getShortNames   sources   exec_sqls   tables	   table_refs
   type_images   format_images   numeros   uid_refs
   ref_objects   Trues   existss   messages   oss   sep(   s   selfs	   new_images   source(    (    s   file_upload.pys   uploadFromFile{   s     >		c         C   s*   |  i o d |  i |  i f Sn t Sd  S(   Ns   %s/%s(   s   selfs
   fileExistss	   http_paths   sources   False(   s   self(    (    s   file_upload.pys   getUrl   s    
c         C   s*   |  i o d |  i |  i f Sn t Sd  S(   Ns   %s/%s(   s   selfs
   fileExistss   paths   sources   False(   s   self(    (    s   file_upload.pys   getPath   s    
c         C   s$   d |  i |  i |  i |  i f Sd S(   s)   
		Builds image name without extension
		s   %s_%s_%s_%sN(   s   selfs   uid_refs
   type_images   format_images   numero(   s   self(    (    s   file_upload.pys   getShortName   s     c         C   s   |  i   o t |  _ y9 |  i d |  i |  i |  i |  i |  i	 |  i
 f  Wn n Xy' t i d |  i t i |  i f  Wn n Xt Sn t Sd  S(   Nsn   
				DELETE FROM %s
				WHERE %s = %s AND ref_type_image = %s AND ref_format_image = %s AND numero = %s ;
				s   %s%s%s(   s   selfs
   fileExistss   Falses   existss   exec_sqls   tables	   table_refs   uid_refs
   type_images   format_images   numeros   oss   removes   paths   seps   sources   True(   s   self(    (    s   file_upload.pys   remove   s    	9'c         C   s   |  i   o t Sn d | |  i t |  i  f } |  i i	   } |  i d |  i |  i | | |  i |  i |  i | |  i |  i f
  oj |  i d |  i | |  i f  | |  _ t i d |  i t i |  i f d |  i t i | f  t Sn t Sd  S(   Ns   %s%ss   
		INSERT INTO %s (uid, source, ref_type_image, ref_format_image, numero, %s, frozen, ref_object)
		VALUES ('%s', '%s', '%s', '%s', '%s', '%s', 1, (SELECT ref_object FROM %s WHERE source = '%s' AND frozen = 0 ORDER BY datemodif LIMIT 1));
		sB   UPDATE %s SET ref_object = '%s' WHERE source = '%s' AND frozen = 0s   %s%s%s(   s   selfs
   fileExistss   Falses   new_uid_refs   sources   lens   uid_refs
   new_sources	   aq_parents   _get_next_uids   uid_copys   exec_sqls   tables	   table_refs
   type_images   format_images   numeros
   ref_objects   shutils   copyfiles   paths   oss   seps   True(   s   selfs   new_uid_refs
   new_sources   uid_copy(    (    s   file_upload.pys   copy   s     G 	9(   s   __name__s
   __module__s   __doc__s	   meta_types   Nones   __init__s   manage_afterAdds   updateFromSQLs
   fileExistss   uploadFromFiles   getUrls   getPaths   getShortNames   removes   copy(    (    (    s   file_upload.pys   SQLFSStoredImageK   s    								s   SQLFSStoredImageManagerc           B   sG   t  Z d  Z e d  Z d   Z d   Z d   Z d   Z d   Z	 RS(   s   
	c         C   s(   t  i |  |  | o | |  _ n d  S(   N(   s   Maps   __init__s   selfs   ids   connection_id(   s   selfs   ids   connection_id(    (    s   file_upload.pys   __init__   s    c	      
   C   sE   t  | | | | | | | | |  i
 	 }	 |	 i   }
 |	 |  |
 <|
 Sd  S(   N(   s   SQLFSStoredImages   paths	   http_paths   tables	   table_refs   uids
   type_images   format_images   numeros   selfs   connection_ids   stored_images   getShortNames   image_id(   s   selfs   paths	   http_paths   tables	   table_refs   uids
   type_images   format_images   numeros   stored_images   image_id(    (    s   file_upload.pys   manageImage   s    '
c         C   s   y |  | SWn t Sn Xd  S(   N(   s   selfs   image_ids   False(   s   selfs   image_id(    (    s   file_upload.pys   getImage   s    c         C   s4   y" |  i |  i   |  | =t SWn t Sn Xd  S(   N(   s   selfs   getImages   image_ids   removes   Trues   False(   s   selfs   image_id(    (    s   file_upload.pys   deleteImage   s    c         C   s   t  t  Sd  S(   N(   s   lens   images(   s   self(    (    s   file_upload.pys   __len__   s    c         C   s<   x5 |  i i   D]$ } | i d j o | i   q q Wd  S(   Ns   SQLFSStoredImage(   s   selfs   aq_inners   valuess   objects	   meta_types   updateFromSQL(   s   selfs   object(    (    s   file_upload.pys   updateImagesFromSQL   s     (
   s   __name__s
   __module__s   __doc__s   Nones   __init__s   manageImages   getImages   deleteImages   __len__s   updateImagesFromSQL(    (    (    s   file_upload.pys   SQLFSStoredImageManager   s    				(   s   __doc__s   Products.PimenTechLibCommon.dbps   DBPs   Products.PimenTechLibCommon.maps   Maps   oss   shutils   OFS.SimpleItems   FileUploadManagers   upload_images
   SimpleItems   SQLFSStoredImages   SQLFSStoredImageManager(   s   Maps   SQLFSStoredImages   upload_images   DBPs   shutils   oss   SQLFSStoredImageManagers   FileUploadManager(    (    s   file_upload.pys   ?   s   			w
