mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-04 03:27:00 -05:00 
			
		
		
		
	Fix Linux installer
This commit is contained in:
		
							parent
							
								
									7325a69fe3
								
							
						
					
					
						commit
						6429bbd65a
					
				
							
								
								
									
										196
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										196
									
								
								setup.py
									
									
									
									
									
								
							@ -18,7 +18,6 @@ sys.path.append('src')
 | 
				
			|||||||
from libprs500 import __version__ as VERSION
 | 
					from libprs500 import __version__ as VERSION
 | 
				
			||||||
from libprs500 import __appname__ as APPNAME
 | 
					from libprs500 import __appname__ as APPNAME
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
entry_points = {
 | 
					entry_points = {
 | 
				
			||||||
        'console_scripts': [ \
 | 
					        'console_scripts': [ \
 | 
				
			||||||
                             'prs500   = libprs500.devices.prs500.cli.main:main', \
 | 
					                             'prs500   = libprs500.devices.prs500.cli.main:main', \
 | 
				
			||||||
@ -64,19 +63,9 @@ main_functions = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    from setuptools import setup, find_packages
 | 
					    from setuptools import setup, find_packages
 | 
				
			||||||
 | 
					    import subprocess
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    if sys.hexversion < 0x2050000:
 | 
					    entry_points['console_scripts'].append('libprs500_postinstall = libprs500.linux:post_install')
 | 
				
			||||||
        print >> sys.stderr, "You must use python >= 2.5 Try invoking this script as python2.5 setup.py."
 | 
					 | 
				
			||||||
        print >> sys.stderr, "If you are using easy_install, try easy_install-2.5"
 | 
					 | 
				
			||||||
        sys.exit(1)
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
    try:
 | 
					 | 
				
			||||||
      from PIL import Image
 | 
					 | 
				
			||||||
    except ImportError:
 | 
					 | 
				
			||||||
      import Image
 | 
					 | 
				
			||||||
      print >>sys.stderr, "You do not have the Python Imaging Library correctly installed."
 | 
					 | 
				
			||||||
      sys.exit(1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    setup(
 | 
					    setup(
 | 
				
			||||||
          name='libprs500', 
 | 
					          name='libprs500', 
 | 
				
			||||||
@ -128,182 +117,5 @@ if __name__ == '__main__':
 | 
				
			|||||||
            ]
 | 
					            ]
 | 
				
			||||||
         )
 | 
					         )
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    if '--uninstall' in ' '.join(sys.argv[1:]):
 | 
					    if 'develop' in ' '.join(sys.argv):
 | 
				
			||||||
        sys.exit(0)
 | 
					        subprocess.check_call('libprs500_postinstall', shell=True)
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    try:
 | 
					 | 
				
			||||||
      import PyQt4
 | 
					 | 
				
			||||||
    except ImportError:
 | 
					 | 
				
			||||||
      print "You do not have PyQt4 installed. The GUI will not work.", \
 | 
					 | 
				
			||||||
            "You can obtain PyQt4 from http://www.riverbankcomputing.co.uk/pyqt/download.php"
 | 
					 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
      import PyQt4.QtCore
 | 
					 | 
				
			||||||
      if PyQt4.QtCore.PYQT_VERSION < 0x40101:
 | 
					 | 
				
			||||||
        print "WARNING: The GUI needs PyQt >= 4.1.1"
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    import os
 | 
					 | 
				
			||||||
    def options(parse_options):
 | 
					 | 
				
			||||||
        options, args, parser = parse_options(['dummy']) 
 | 
					 | 
				
			||||||
        options = parser.option_list
 | 
					 | 
				
			||||||
        for group in parser.option_groups:
 | 
					 | 
				
			||||||
            options += group.option_list
 | 
					 | 
				
			||||||
        opts = []
 | 
					 | 
				
			||||||
        for opt in options:
 | 
					 | 
				
			||||||
            opts.extend(opt._short_opts)
 | 
					 | 
				
			||||||
            opts.extend(opt._long_opts)
 | 
					 | 
				
			||||||
        return opts
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    def opts_and_exts(name, op, exts):
 | 
					 | 
				
			||||||
        opts = ' '.join(options(op))
 | 
					 | 
				
			||||||
        exts.extend([i.upper() for i in exts])
 | 
					 | 
				
			||||||
        exts='|'.join(exts)
 | 
					 | 
				
			||||||
        return '_'+name+'()'+\
 | 
					 | 
				
			||||||
    '''
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        local cur prev opts
 | 
					 | 
				
			||||||
        COMPREPLY=()
 | 
					 | 
				
			||||||
        cur="${COMP_WORDS[COMP_CWORD]}"
 | 
					 | 
				
			||||||
        prev="${COMP_WORDS[COMP_CWORD-1]}"
 | 
					 | 
				
			||||||
        opts="%s"
 | 
					 | 
				
			||||||
        pics="@(jpg|jpeg|png|gif|bmp|JPG|JPEG|PNG|GIF|BMP)"
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
        case "${prev}" in
 | 
					 | 
				
			||||||
          --cover )
 | 
					 | 
				
			||||||
               _filedir "${pics}"
 | 
					 | 
				
			||||||
               return 0
 | 
					 | 
				
			||||||
               ;;
 | 
					 | 
				
			||||||
        esac
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
        case "${cur}" in
 | 
					 | 
				
			||||||
          --cover )
 | 
					 | 
				
			||||||
             _filedir "${pics}"
 | 
					 | 
				
			||||||
             return 0
 | 
					 | 
				
			||||||
             ;;
 | 
					 | 
				
			||||||
          -* )
 | 
					 | 
				
			||||||
             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
 | 
					 | 
				
			||||||
             return 0
 | 
					 | 
				
			||||||
             ;;
 | 
					 | 
				
			||||||
          *  )
 | 
					 | 
				
			||||||
            _filedir '@(%s)'
 | 
					 | 
				
			||||||
            return 0
 | 
					 | 
				
			||||||
            ;;
 | 
					 | 
				
			||||||
        esac
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    complete -o filenames -F _'''%(opts,exts) + name + ' ' + name +"\n\n"
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    if os.access('/etc/bash_completion.d', os.W_OK):
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            print 'Setting up bash completion...',
 | 
					 | 
				
			||||||
            sys.stdout.flush()
 | 
					 | 
				
			||||||
            from libprs500.ebooks.lrf.html.convert_from import parse_options as htmlop
 | 
					 | 
				
			||||||
            from libprs500.ebooks.lrf.txt.convert_from import parse_options as txtop
 | 
					 | 
				
			||||||
            from libprs500.ebooks.lrf.meta import parse_options as metaop
 | 
					 | 
				
			||||||
            f = open('/etc/bash_completion.d/libprs500', 'wb')
 | 
					 | 
				
			||||||
            f.write('# libprs500 Bash Shell Completion\n')
 | 
					 | 
				
			||||||
            f.write(opts_and_exts('html2lrf', htmlop, 
 | 
					 | 
				
			||||||
                                  ['htm', 'html', 'xhtml', 'xhtm', 'rar', 'zip']))
 | 
					 | 
				
			||||||
            f.write(opts_and_exts('txt2lrf', txtop, ['txt']))
 | 
					 | 
				
			||||||
            f.write(opts_and_exts('lrf-meta', metaop, ['lrf']))
 | 
					 | 
				
			||||||
            f.write('''
 | 
					 | 
				
			||||||
    _prs500_ls()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
      local pattern search listing prefix
 | 
					 | 
				
			||||||
      pattern="$1"
 | 
					 | 
				
			||||||
      search="$1"
 | 
					 | 
				
			||||||
      if [[ -n "{$pattern}" ]]; then
 | 
					 | 
				
			||||||
        if [[ "${pattern:(-1)}" == "/" ]]; then
 | 
					 | 
				
			||||||
          pattern=""
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
          pattern="$(basename ${pattern} 2> /dev/null)"
 | 
					 | 
				
			||||||
          search="$(dirname ${search} 2> /dev/null)"
 | 
					 | 
				
			||||||
        fi
 | 
					 | 
				
			||||||
      fi
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
      if [[  "x${search}" == "x" || "x${search}" == "x." ]]; then
 | 
					 | 
				
			||||||
        search="/"
 | 
					 | 
				
			||||||
      fi
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
      listing="$(prs500 ls ${search} 2>/dev/null)"
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
      prefix="${search}"
 | 
					 | 
				
			||||||
      if [[ "x${prefix:(-1)}" != "x/" ]]; then
 | 
					 | 
				
			||||||
        prefix="${prefix}/"
 | 
					 | 
				
			||||||
      fi
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
      echo $(compgen -P "${prefix}" -W "${listing}" "${pattern}") 
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    _prs500()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
      local cur prev 
 | 
					 | 
				
			||||||
      cur="${COMP_WORDS[COMP_CWORD]}"
 | 
					 | 
				
			||||||
      prev="${COMP_WORDS[COMP_CWORD-1]}"
 | 
					 | 
				
			||||||
      COMPREPLY=()
 | 
					 | 
				
			||||||
      case "${prev}" in
 | 
					 | 
				
			||||||
        ls|rm|mkdir|touch|cat )        
 | 
					 | 
				
			||||||
            COMPREPLY=( $(_prs500_ls "${cur}") )
 | 
					 | 
				
			||||||
            return 0
 | 
					 | 
				
			||||||
            ;;
 | 
					 | 
				
			||||||
        cp )
 | 
					 | 
				
			||||||
            if [[ ${cur} == prs500:* ]]; then
 | 
					 | 
				
			||||||
              COMPREPLY=( $(_prs500_ls "${cur:7}") )
 | 
					 | 
				
			||||||
              return 0
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
              _filedir
 | 
					 | 
				
			||||||
              return 0
 | 
					 | 
				
			||||||
            fi
 | 
					 | 
				
			||||||
            ;;
 | 
					 | 
				
			||||||
        prs500 )
 | 
					 | 
				
			||||||
            COMPREPLY=( $(compgen -W "cp ls rm mkdir touch cat info books df" "${cur}") )
 | 
					 | 
				
			||||||
            return 0
 | 
					 | 
				
			||||||
            ;;
 | 
					 | 
				
			||||||
        * )
 | 
					 | 
				
			||||||
            if [[ ${cur} == prs500:* ]]; then
 | 
					 | 
				
			||||||
              COMPREPLY=( $(_prs500_ls "${cur:7}") )
 | 
					 | 
				
			||||||
              return 0
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
              if [[ ${prev} == prs500:* ]]; then
 | 
					 | 
				
			||||||
                _filedir
 | 
					 | 
				
			||||||
                return 0
 | 
					 | 
				
			||||||
              else
 | 
					 | 
				
			||||||
                COMPREPLY=( $(compgen -W "prs500:" "${cur}") )
 | 
					 | 
				
			||||||
                return 0
 | 
					 | 
				
			||||||
              fi
 | 
					 | 
				
			||||||
              return 0
 | 
					 | 
				
			||||||
            fi
 | 
					 | 
				
			||||||
           ;;
 | 
					 | 
				
			||||||
      esac
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    complete -o nospace  -F _prs500 prs500
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    ''')
 | 
					 | 
				
			||||||
            f.close()
 | 
					 | 
				
			||||||
            print 'done'
 | 
					 | 
				
			||||||
        except:
 | 
					 | 
				
			||||||
            import traceback
 | 
					 | 
				
			||||||
            traceback.print_exc()
 | 
					 | 
				
			||||||
            print 'failed'
 | 
					 | 
				
			||||||
                    
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    if os.access('/etc/udev/rules.d', os.W_OK):
 | 
					 | 
				
			||||||
      from subprocess import check_call
 | 
					 | 
				
			||||||
      print 'Trying to setup udev rules...',
 | 
					 | 
				
			||||||
      sys.stdout.flush()
 | 
					 | 
				
			||||||
      udev = open('/etc/udev/rules.d/95-libprs500.rules', 'w')
 | 
					 | 
				
			||||||
      udev.write('''# Sony Reader PRS-500\n'''
 | 
					 | 
				
			||||||
                 '''BUS=="usb", SYSFS{idProduct}=="029b", SYSFS{idVendor}=="054c", MODE="660", GROUP="plugdev"\n'''
 | 
					 | 
				
			||||||
                 )
 | 
					 | 
				
			||||||
      udev.close()
 | 
					 | 
				
			||||||
      try:
 | 
					 | 
				
			||||||
          check_call('udevstart', shell=True)
 | 
					 | 
				
			||||||
          print 'success'
 | 
					 | 
				
			||||||
      except:
 | 
					 | 
				
			||||||
          try:
 | 
					 | 
				
			||||||
              check_call('/etc/init.d/udev reload', shell=True)
 | 
					 | 
				
			||||||
              print 'success'
 | 
					 | 
				
			||||||
          except:
 | 
					 | 
				
			||||||
              print >>sys.stderr, "Couldn't reload udev, you may have to reboot"
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
@ -13,7 +13,7 @@
 | 
				
			|||||||
##    with this program; if not, write to the Free Software Foundation, Inc.,
 | 
					##    with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
##    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
					##    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
''' E-book management software'''
 | 
					''' E-book management software'''
 | 
				
			||||||
__version__   = "0.3.59"
 | 
					__version__   = "0.3.60"
 | 
				
			||||||
__docformat__ = "epytext"
 | 
					__docformat__ = "epytext"
 | 
				
			||||||
__author__    = "Kovid Goyal <kovid@kovidgoyal.net>"
 | 
					__author__    = "Kovid Goyal <kovid@kovidgoyal.net>"
 | 
				
			||||||
__appname__   = 'libprs500'
 | 
					__appname__   = 'libprs500'
 | 
				
			||||||
 | 
				
			|||||||
@ -60,6 +60,8 @@ def main():
 | 
				
			|||||||
            l = glob.glob(os.path.join(tdir, '*toc*.htm*'))
 | 
					            l = glob.glob(os.path.join(tdir, '*toc*.htm*'))
 | 
				
			||||||
            if not l:
 | 
					            if not l:
 | 
				
			||||||
                l = glob.glob(os.path.join(tdir, '*top*.htm*'))
 | 
					                l = glob.glob(os.path.join(tdir, '*top*.htm*'))
 | 
				
			||||||
 | 
					            if not l:
 | 
				
			||||||
 | 
					                l = glob.glob(os.path.join(tdir, '*contents*.htm*'))
 | 
				
			||||||
            if not l:
 | 
					            if not l:
 | 
				
			||||||
                l = glob.glob(os.path.join(tdir, '*.htm*'))
 | 
					                l = glob.glob(os.path.join(tdir, '*.htm*'))
 | 
				
			||||||
                if not l:
 | 
					                if not l:
 | 
				
			||||||
 | 
				
			|||||||
@ -594,7 +594,7 @@ def parse_options(argv=None, cli=True):
 | 
				
			|||||||
                    help="Extract thumbnail from LRF file")
 | 
					                    help="Extract thumbnail from LRF file")
 | 
				
			||||||
    parser.add_option("-p", "--page", action="store", type="string", \
 | 
					    parser.add_option("-p", "--page", action="store", type="string", \
 | 
				
			||||||
                    dest="page", help="Don't know what this is for")
 | 
					                    dest="page", help="Don't know what this is for")
 | 
				
			||||||
    options, args = parser.parse_args()
 | 
					    options, args = parser.parse_args(args=argv)
 | 
				
			||||||
    if len(args) != 1:
 | 
					    if len(args) != 1:
 | 
				
			||||||
        if cli:
 | 
					        if cli:
 | 
				
			||||||
            parser.print_help()
 | 
					            parser.print_help()
 | 
				
			||||||
 | 
				
			|||||||
@ -24,8 +24,10 @@ from libprs500.ebooks.lrf.html.convert_from import parse_options as html_parse_o
 | 
				
			|||||||
from libprs500.ebooks.lrf.html.convert_from import process_file
 | 
					from libprs500.ebooks.lrf.html.convert_from import process_file
 | 
				
			||||||
from libprs500.ebooks.markdown import markdown
 | 
					from libprs500.ebooks.markdown import markdown
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def parse_options(cli=True):
 | 
					def parse_options(argv=None, cli=True):
 | 
				
			||||||
    """ CLI for txt -> lrf conversions """
 | 
					    """ CLI for txt -> lrf conversions """
 | 
				
			||||||
 | 
					    if not argv:
 | 
				
			||||||
 | 
					        argv = sys.argv[1:]
 | 
				
			||||||
    parser = option_parser(
 | 
					    parser = option_parser(
 | 
				
			||||||
        """usage: %prog [options] mybook.txt
 | 
					        """usage: %prog [options] mybook.txt
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
@ -37,7 +39,7 @@ def parse_options(cli=True):
 | 
				
			|||||||
              'the text in mybook.txt. Default encoding is %default'
 | 
					              'the text in mybook.txt. Default encoding is %default'
 | 
				
			||||||
    parser.add_option('-e', '--encoding', action='store', type='string', \
 | 
					    parser.add_option('-e', '--encoding', action='store', type='string', \
 | 
				
			||||||
                      dest='encoding', help=enchelp, default=defenc)
 | 
					                      dest='encoding', help=enchelp, default=defenc)
 | 
				
			||||||
    options, args = parser.parse_args()
 | 
					    options, args = parser.parse_args(args=argv)
 | 
				
			||||||
    if len(args) != 1:
 | 
					    if len(args) != 1:
 | 
				
			||||||
        if cli:
 | 
					        if cli:
 | 
				
			||||||
            parser.print_help()
 | 
					            parser.print_help()
 | 
				
			||||||
 | 
				
			|||||||
@ -698,11 +698,3 @@ class LibraryDatabase(object):
 | 
				
			|||||||
        self.conn.execute('INSERT INTO books_ratings_link(book, rating) VALUES (?,?)', (id, rat))
 | 
					        self.conn.execute('INSERT INTO books_ratings_link(book, rating) VALUES (?,?)', (id, rat))
 | 
				
			||||||
        self.conn.commit()
 | 
					        self.conn.commit()
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
if __name__ == '__main__':    
 | 
					 | 
				
			||||||
    from IPython.Shell import IPShellEmbed
 | 
					 | 
				
			||||||
    ipshell = IPShellEmbed([],
 | 
					 | 
				
			||||||
                       banner = 'Dropping into IPython',
 | 
					 | 
				
			||||||
                       exit_msg = 'Leaving Interpreter, back to program.')
 | 
					 | 
				
			||||||
    db = LibraryDatabase('/home/kovid/library1.db')
 | 
					 | 
				
			||||||
    conn = db.conn
 | 
					 | 
				
			||||||
    ipshell()
 | 
					 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										194
									
								
								src/libprs500/linux.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										194
									
								
								src/libprs500/linux.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,194 @@
 | 
				
			|||||||
 | 
					##    Copyright (C) 2007 Kovid Goyal kovid@kovidgoyal.net
 | 
				
			||||||
 | 
					##    This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					##    it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					##    the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					##    (at your option) any later version.
 | 
				
			||||||
 | 
					##
 | 
				
			||||||
 | 
					##    This program 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 General Public License for more details.
 | 
				
			||||||
 | 
					##
 | 
				
			||||||
 | 
					##    You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					##    with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					##    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.Warning
 | 
				
			||||||
 | 
					''' Post installation script for linux '''
 | 
				
			||||||
 | 
					import sys, os
 | 
				
			||||||
 | 
					from subprocess import check_call
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def options(parse_options):
 | 
				
			||||||
 | 
					    options, args, parser = parse_options(['dummy'], cli=False) 
 | 
				
			||||||
 | 
					    options = parser.option_list
 | 
				
			||||||
 | 
					    for group in parser.option_groups:
 | 
				
			||||||
 | 
					        options += group.option_list
 | 
				
			||||||
 | 
					    opts = []
 | 
				
			||||||
 | 
					    for opt in options:
 | 
				
			||||||
 | 
					        opts.extend(opt._short_opts)
 | 
				
			||||||
 | 
					        opts.extend(opt._long_opts)
 | 
				
			||||||
 | 
					    return opts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def opts_and_exts(name, op, exts):
 | 
				
			||||||
 | 
					    opts = ' '.join(options(op))
 | 
				
			||||||
 | 
					    exts.extend([i.upper() for i in exts])
 | 
				
			||||||
 | 
					    exts='|'.join(exts)
 | 
				
			||||||
 | 
					    return '_'+name+'()'+\
 | 
				
			||||||
 | 
					'''
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    local cur prev opts
 | 
				
			||||||
 | 
					    COMPREPLY=()
 | 
				
			||||||
 | 
					    cur="${COMP_WORDS[COMP_CWORD]}"
 | 
				
			||||||
 | 
					    prev="${COMP_WORDS[COMP_CWORD-1]}"
 | 
				
			||||||
 | 
					    opts="%s"
 | 
				
			||||||
 | 
					    pics="@(jpg|jpeg|png|gif|bmp|JPG|JPEG|PNG|GIF|BMP)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    case "${prev}" in
 | 
				
			||||||
 | 
					      --cover )
 | 
				
			||||||
 | 
					           _filedir "${pics}"
 | 
				
			||||||
 | 
					           return 0
 | 
				
			||||||
 | 
					           ;;
 | 
				
			||||||
 | 
					    esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    case "${cur}" in
 | 
				
			||||||
 | 
					      --cover )
 | 
				
			||||||
 | 
					         _filedir "${pics}"
 | 
				
			||||||
 | 
					         return 0
 | 
				
			||||||
 | 
					         ;;
 | 
				
			||||||
 | 
					      -* )
 | 
				
			||||||
 | 
					         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
 | 
				
			||||||
 | 
					         return 0
 | 
				
			||||||
 | 
					         ;;
 | 
				
			||||||
 | 
					      *  )
 | 
				
			||||||
 | 
					        _filedir '@(%s)'
 | 
				
			||||||
 | 
					        return 0
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					complete -o filenames -F _'''%(opts,exts) + name + ' ' + name +"\n\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def setup_completion():
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        print 'Setting up bash completion...',
 | 
				
			||||||
 | 
					        sys.stdout.flush()
 | 
				
			||||||
 | 
					        from libprs500.ebooks.lrf.html.convert_from import parse_options as htmlop
 | 
				
			||||||
 | 
					        from libprs500.ebooks.lrf.txt.convert_from import parse_options as txtop
 | 
				
			||||||
 | 
					        from libprs500.ebooks.lrf.meta import parse_options as metaop
 | 
				
			||||||
 | 
					        f = open('/etc/bash_completion.d/libprs500', 'wb')
 | 
				
			||||||
 | 
					        f.write('# libprs500 Bash Shell Completion\n')
 | 
				
			||||||
 | 
					        f.write(opts_and_exts('html2lrf', htmlop, 
 | 
				
			||||||
 | 
					                              ['htm', 'html', 'xhtml', 'xhtm', 'rar', 'zip']))
 | 
				
			||||||
 | 
					        f.write(opts_and_exts('txt2lrf', txtop, ['txt']))
 | 
				
			||||||
 | 
					        f.write(opts_and_exts('lit2lrf', txtop, ['lit']))
 | 
				
			||||||
 | 
					        f.write(opts_and_exts('lrf-meta', metaop, ['lrf']))
 | 
				
			||||||
 | 
					        f.write('''
 | 
				
			||||||
 | 
					_prs500_ls()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  local pattern search listing prefix
 | 
				
			||||||
 | 
					  pattern="$1"
 | 
				
			||||||
 | 
					  search="$1"
 | 
				
			||||||
 | 
					  if [[ -n "{$pattern}" ]]; then
 | 
				
			||||||
 | 
					    if [[ "${pattern:(-1)}" == "/" ]]; then
 | 
				
			||||||
 | 
					      pattern=""
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      pattern="$(basename ${pattern} 2> /dev/null)"
 | 
				
			||||||
 | 
					      search="$(dirname ${search} 2> /dev/null)"
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if [[  "x${search}" == "x" || "x${search}" == "x." ]]; then
 | 
				
			||||||
 | 
					    search="/"
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  listing="$(prs500 ls ${search} 2>/dev/null)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  prefix="${search}"
 | 
				
			||||||
 | 
					  if [[ "x${prefix:(-1)}" != "x/" ]]; then
 | 
				
			||||||
 | 
					    prefix="${prefix}/"
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  echo $(compgen -P "${prefix}" -W "${listing}" "${pattern}") 
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_prs500()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  local cur prev 
 | 
				
			||||||
 | 
					  cur="${COMP_WORDS[COMP_CWORD]}"
 | 
				
			||||||
 | 
					  prev="${COMP_WORDS[COMP_CWORD-1]}"
 | 
				
			||||||
 | 
					  COMPREPLY=()
 | 
				
			||||||
 | 
					  case "${prev}" in
 | 
				
			||||||
 | 
					    ls|rm|mkdir|touch|cat )        
 | 
				
			||||||
 | 
					        COMPREPLY=( $(_prs500_ls "${cur}") )
 | 
				
			||||||
 | 
					        return 0
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    cp )
 | 
				
			||||||
 | 
					        if [[ ${cur} == prs500:* ]]; then
 | 
				
			||||||
 | 
					          COMPREPLY=( $(_prs500_ls "${cur:7}") )
 | 
				
			||||||
 | 
					          return 0
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					          _filedir
 | 
				
			||||||
 | 
					          return 0
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    prs500 )
 | 
				
			||||||
 | 
					        COMPREPLY=( $(compgen -W "cp ls rm mkdir touch cat info books df" "${cur}") )
 | 
				
			||||||
 | 
					        return 0
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    * )
 | 
				
			||||||
 | 
					        if [[ ${cur} == prs500:* ]]; then
 | 
				
			||||||
 | 
					          COMPREPLY=( $(_prs500_ls "${cur:7}") )
 | 
				
			||||||
 | 
					          return 0
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					          if [[ ${prev} == prs500:* ]]; then
 | 
				
			||||||
 | 
					            _filedir
 | 
				
			||||||
 | 
					            return 0
 | 
				
			||||||
 | 
					          else
 | 
				
			||||||
 | 
					            COMPREPLY=( $(compgen -W "prs500:" "${cur}") )
 | 
				
			||||||
 | 
					            return 0
 | 
				
			||||||
 | 
					          fi
 | 
				
			||||||
 | 
					          return 0
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					       ;;
 | 
				
			||||||
 | 
					  esac
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					complete -o nospace  -F _prs500 prs500
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					''')
 | 
				
			||||||
 | 
					        f.close()
 | 
				
			||||||
 | 
					        print 'done'
 | 
				
			||||||
 | 
					    except:
 | 
				
			||||||
 | 
					        print 'failed'
 | 
				
			||||||
 | 
					        import traceback
 | 
				
			||||||
 | 
					        traceback.print_exc()
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					def setup_udev_rules():
 | 
				
			||||||
 | 
					    print 'Trying to setup udev rules...',
 | 
				
			||||||
 | 
					    sys.stdout.flush()
 | 
				
			||||||
 | 
					    udev = open('/etc/udev/rules.d/95-libprs500.rules', 'w')
 | 
				
			||||||
 | 
					    udev.write('''# Sony Reader PRS-500\n'''
 | 
				
			||||||
 | 
					             '''BUS=="usb", SYSFS{idProduct}=="029b", SYSFS{idVendor}=="054c", MODE="660", GROUP="plugdev"\n'''
 | 
				
			||||||
 | 
					             )
 | 
				
			||||||
 | 
					    udev.close()
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        check_call('udevstart', shell=True)
 | 
				
			||||||
 | 
					        print 'success'
 | 
				
			||||||
 | 
					    except:
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            check_call('/etc/init.d/udev reload', shell=True)
 | 
				
			||||||
 | 
					            print 'success'
 | 
				
			||||||
 | 
					        except:
 | 
				
			||||||
 | 
					          print >>sys.stderr, "Couldn't reload udev, you may have to reboot"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def post_install():
 | 
				
			||||||
 | 
					    if os.geteuid() != 0:
 | 
				
			||||||
 | 
					        print >> sys.stderr, 'You must be root to run this command.'
 | 
				
			||||||
 | 
					        sys.exit(1)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    setup_udev_rules()
 | 
				
			||||||
 | 
					    setup_completion()
 | 
				
			||||||
 | 
					         
 | 
				
			||||||
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 | 
					    post_install()           
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -107,7 +107,7 @@ def main():
 | 
				
			|||||||
    print 'Uploading installers...'
 | 
					    print 'Uploading installers...'
 | 
				
			||||||
    upload_installers(exe, dmg)
 | 
					    upload_installers(exe, dmg)
 | 
				
			||||||
    print 'Uploading to PyPI'
 | 
					    print 'Uploading to PyPI'
 | 
				
			||||||
    check_call('''python setup.py register sdist bdist_egg upload''')
 | 
					    check_call('''python setup.py register bdist_egg upload''')
 | 
				
			||||||
    upload_docs()
 | 
					    upload_docs()
 | 
				
			||||||
    check_call('''rm -rf dist/* build/*''')
 | 
					    check_call('''rm -rf dist/* build/*''')
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user