Package imagizer :: Module setup
[hide private]
[frames] | no frames]

Source Code for Module imagizer.setup

  1  #!/usr/bin/env python  
  2  # -*- coding: UTF8 -*- 
  3  #******************************************************************************\ 
  4  #* $Source$ 
  5  #* $Id$ 
  6  #* 
  7  #* Copyright (C) 2006,  Jérome Kieffer <kieffer@terre-adelie.org> 
  8  #* Conception : Jérôme KIEFFER, Mickael Profeta & Isabelle Letard 
  9  #* Licence GPL v2 
 10  #* 
 11  #* This program is free software; you can redistribute it and/or modify 
 12  #* it under the terms of the GNU General Public License as published by 
 13  #* the Free Software Foundation; either version 2 of the License, or 
 14  #* (at your option) any later version. 
 15  #* 
 16  #* This program is distributed in the hope that it will be useful, 
 17  #* but WITHOUT ANY WARRANTY; without even the implied warranty of 
 18  #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 19  #* GNU General Public License for more details. 
 20  #* 
 21  #* You should have received a copy of the GNU General Public License 
 22  #* along with this program; if not, write to the Free Software 
 23  #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 24  #* 
 25  #*****************************************************************************/ 
 26   
 27  """ 
 28  The setup.py script allows to install Imagizer regardless to the operating system 
 29  """ 
 30   
 31  from distutils.core import setup 
 32  import os, sys, glob, distutils.sysconfig, shutil, locale 
 33   
 34  #here we detect the OS runnng the program so that we can call exftran in the right way 
 35  installdir = os.path.join(distutils.sysconfig.get_python_lib(), "imagizer") 
 36  if os.name == 'nt': #sys.platform == 'win32': 
 37      execexiftran = os.path.join(os.getcwd(), "bin", "exiftran.exe") 
 38      ConfFile = [os.path.join(os.getenv("ALLUSERSPROFILE"), "imagizer.conf"), os.path.join(os.getenv("USERPROFILE"), "imagizer.conf")] 
 39      shutil.copy('selector', 'selector.py') 
 40      shutil.copy('generator', 'generator.py') 
 41      shutil.copy('imagizer.conf-windows', 'imagizer.conf') 
 42      scripts = ['selector.py', "generator.py", "NommeVideo.py", "ConvertIndex.descLatin1ToUTF8.py"] 
 43   
 44  elif os.name == 'posix': 
 45  #    shutil.copy(os.path.join(os.getcwd(),"bin","exiftran"+str(int(1+log(os.sys.maxint+1)/log(2)))),os.path.join(os.getcwd(),"bin","exiftran")) 
 46      ConfFile = ["/etc/imagizer.conf", os.path.join(os.getenv("HOME"), ".imagizer")] 
 47      scripts = ['selector', "generator", "NommeVideo.py", "ConvertIndex.descLatin1ToUTF8.py"] 
 48      execexiftran = os.path.join(os.getcwd(), "bin", "exiftran") 
 49      os.chmod(execexiftran, 509) #509 = 775 in octal 
 50      shutil.copy('imagizer.conf-unix', 'imagizer.conf') 
 51   
 52  else: 
 53      raise "Your platform does not seem to be an Unix nor a M$ Windows.\nI am sorry but the exiftran binary is necessary to run selector, and exiftran is probably not available for you plateform. If you have exiftran installed, please contact the developper to correct that bug, kieffer at terre-adelie dot org" 
 54      sys.exit(1) 
 55   
 56  configured = False 
 57  for i in ConfFile: 
 58      if os.path.isfile(i):configured = True 
 59   
 60   
 61  ### trick to make an auto-install under windows : 
 62  if len(sys.argv) == 1: 
 63      sys.argv.append("install") 
 64   
 65   
 66   
 67  setup(name='Imagizer', 
 68      version='1.0', 
 69      author='Jerome Kieffer', 
 70      author_email='Jerome.Kieffer@terre-adelie.org', 
 71      url='http://wiki.terre-adelie.org/Imagizer', 
 72      description="Imagizer is a manager for a repository of photos", 
 73      license='GNU GPL v2', 
 74      scripts=scripts, 
 75      data_files=[ 
 76          (installdir, ["selector.glade", execexiftran] + 
 77          glob.glob(os.path.join("pixmaps", "*.png")) + 
 78          glob.glob(os.path.join("pixmaps", "*.ico"))), 
 79          (os.path.split(ConfFile[0])[0], ['imagizer.conf']) 
 80      ], 
 81      packages=['imagizer'], 
 82      package_dir={'imagizer': ''}, 
 83      ) 
 84  os.remove("imagizer.conf") 
 85   
 86  if not configured: 
 87      import config 
 88      config = config.Config() 
 89      config.load(ConfFile) 
 90  #    textinterface = True 
 91  #    try: 
 92  #        import pygtk ; pygtk.require('2.0') 
 93  #        import gtk, gtk.glade 
 94          #textinterface = False 
 95  #    except ImportError: 
 96   
 97  #        textinterface = True 
 98  #    if textinterface: 
 99      while True: 
100          print "Enter le chemin du repertoire racine du serveur WEB :" 
101          config.WebRepository = raw_input("[%s] :" % config.WebRepository) 
102          if os.path.isdir(config.WebRepository): 
103              break 
104          print "No Such Directory" 
105  #    else: 
106  #        from dirchooser import WarningSc 
107  #        W = WarningSc(config.WebRepository, window="WWW-root") 
108  #        config.WebRepository = W.directory 
109  #        del W 
110      config.Locale, config.Coding = locale.getdefaultlocale() 
111      LANG = os.getenv("LANG") 
112      if LANG: 
113          config.Locale = LANG 
114      config.PrintConfig() 
115      config.SaveConfig("/etc/imagizer.conf") 
116      print "Configuration finished .... Saving it\nYou can modify it in /etc/imagizer.conf" 
117   
118      try: 
119          import pyexiv2 
120      except: 
121          raise ImportError("You should install pyexiv2 by: #aptitude install python-pyexiv2") 
122   
123      try: 
124          import Image, ImageStat, ImageChops, ImageFile 
125      except: 
126          raise ImportError("Selector needs PIL: Python Imaging Library\n PIL is available from http://www.pythonware.com/products/pil/\ninstall it by # aptitude install python-imaging") 
127      try: 
128          import pygtk ; pygtk.require('2.0') 
129          import gtk, gtk.glade 
130      except ImportError: 
131          raise ImportError("Selector needs pygtk and glade-2 available from http://www.pygtk.org/\nPLease install it with # aptitude install python-glade2") 
132