File calibre-setup.install.py.diff of Package calibre

Index: calibre/setup/install.py
===================================================================
--- calibre.orig/setup/install.py	2012-06-08 07:17:56.000000000 +0200
+++ calibre/setup/install.py	2012-06-12 20:44:24.091577428 +0200
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
 from __future__ import with_statement
 
@@ -76,11 +77,13 @@ class Develop(Command):
         opts = self.opts
         if not opts.prefix:
             opts.prefix = sys.prefix
-        for x in ('prefix', 'libdir', 'bindir', 'sharedir', 'staging_root',
-                'staging_libdir', 'staging_bindir', 'staging_sharedir'):
+        for x in ('prefix', 'libdir', 'bindir', 'sharedir', 'mandir',
+                      'staging_root', 'staging_libdir',
+                      'staging_bindir', 'staging_sharedir', 'locale_dir'):
             o = getattr(opts, x, None)
             if o:
                 setattr(opts, x, os.path.abspath(o))
+        self.info( "****", opts, self )
         self.libdir = getattr(opts, 'libdir', None)
         if self.libdir is None:
             self.libdir = self.j(opts.prefix, 'lib')
@@ -88,8 +91,12 @@ class Develop(Command):
         if self.bindir is None:
             self.bindir = self.j(opts.prefix, 'bin')
         self.sharedir = getattr(opts, 'sharedir', None)
+        self.mandir = getattr(opts, 'mandir', None)
+        if self.mandir is None:
+            self.mandir = self.j(opts.prefix, 'share')
         if self.sharedir is None:
             self.sharedir = self.j(opts.prefix, 'share')
+
         if not getattr(opts, 'staging_root', None):
             opts.staging_root = opts.prefix
         self.staging_libdir = getattr(opts, 'staging_libdir', None)
@@ -101,9 +108,17 @@ class Develop(Command):
         self.staging_sharedir = getattr(opts, 'staging_sharedir', None)
         if self.staging_sharedir is None:
             self.staging_sharedir = opts.staging_sharedir = self.j(opts.staging_root, 'share')
+        self.staging_mandir = getattr(opts, 'staging_mandir', None)
+        if self.staging_mandir is None:
+            self.staging_mandir = opts.staging_mandir = self.j(opts.staging_root, 'man')
+        self.staging_localedir = getattr(opts, 'staging_localedir', None)
+        if self.staging_localedir is None:
+            self.staging_localedir = opts.staging_localedir = self.j(opts.staging_root, 'usr/share/locale')
 
         self.staging_libdir = opts.staging_libdir = self.j(self.staging_libdir, 'calibre')
         self.staging_sharedir = opts.staging_sharedir = self.j(self.staging_sharedir, 'calibre')
+        self.staging_mandir = opts.staging_mandir = self.j(self.staging_mandir, '')
+        self.staging_localedir = opts.staging_localedir = self.j(self.staging_localedir, '')
 
         if self.__class__.__name__ == 'Develop':
             self.libdir = self.SRC
@@ -114,6 +129,8 @@ class Develop(Command):
             self.info('INSTALL paths:')
             self.info('\tLIB:', self.staging_libdir)
             self.info('\tSHARE:', self.staging_sharedir)
+            self.staging_mandir =self.j(self.mandir, '')
+            # self.mandir = self.j(opts.staging_root, 'man')
 
 
     def pre_sub_commands(self, opts):
@@ -245,6 +262,11 @@ class Install(Develop):
                     'the launcher scripts. This option controls the prefix '
                     'to which the install will actually copy files. By default '
                     'it is set to the value of --prefix.'))
+        parser.add_option('--staging-mandir',
+            help='Where to put the calibre manpage files. Default is <root>/man')
+        parser.add_option('--staging-locale-dir',
+            dest="staging_localedir",
+            help="Where to put the calibre locale files. Default is <root>/share/locale")
         parser.add_option('--staging-libdir',
             help='Where to put calibre library files. Default is <root>/lib')
         parser.add_option('--staging-bindir',
@@ -253,6 +275,50 @@ class Install(Develop):
             help='Where to put the calibre data files. Default is <root>/share')
         self.add_postinstall_options(parser)
 
+    def install_localefiles(self):
+      """Install the .mo files"""
+      #if not self.locale_dir.startswith( sys.prefix ):
+      #  # We don't want to disturb installation when option --locale-dir is not set
+      #  return
+      locale = os.path.join(self.RESOURCES, "localization/locales")
+      dest = self.staging_localedir
+      self.info("Installing locale files...")
+      self.info("*** locale_dir:", dest)
+      self.info("*** SRC:", self.SRC)
+      self.info("*** DEST:", dest)
+      if not os.path.exists(dest):
+        os.makedirs(dest)
+      for lang in os.listdir( locale ):
+        j = os.path.join(locale, lang)
+        dd = os.path.join(dest, lang)
+        if os.path.exists(dd):
+            shutil.rmtree(dd)
+        lc_message_dest = os.path.join(dest, lang, 'LC_MESSAGES')
+        lc_message = os.path.join(locale, lang, "LC_MESSAGES")
+        self.info("Creating locale directory %s " % lc_message_dest)
+        os.makedirs( lc_message_dest )
+        filedict = { 
+           'iso639.mo': 'iso639.mo',
+           'messages.mo': 'calibre.mo',
+           'qt.qm': '',
+          }
+        for f in os.listdir(lc_message):
+          destfile = filedict.get(f)
+          if destfile != '':
+            self.info("Moving %s -> %s" % (lang, dd))
+            shutil.move(os.path.join(lc_message, f), 
+                        os.path.join(dest, lang, 'LC_MESSAGES', destfile ))
+
+        
+        #shutil.move(os.path.join(locale,i), dest)
+        # Rename that beast:
+        #shutil.move(os.path.join(dest, i, 'LC_MESSAGES/messages.mo'),
+        #            os.path.join(dest, i, 'LC_MESSAGES/calibre.mo'))
+        #os.remove( os.path.join(dest, i, 'LC_MESSAGES/qt.qm' )
+        #shutil.copytree(j, dd )
+      shutil.rmtree(os.path.join(self.RESOURCES, "localization/locales") )
+
+
     def install_files(self):
         dest = self.staging_libdir
         if os.path.exists(dest):
@@ -270,7 +336,11 @@ class Install(Develop):
         dest = self.staging_sharedir
         if os.path.exists(dest):
             shutil.rmtree(dest)
+        
+#        self.install_localefiles()
         self.info('Installing resources to', dest)
+
+        
         shutil.copytree(self.RESOURCES, dest)
         self.manifest.append(dest)