From 0e8bc340eba322d498dc9b7aaa91488abbd43957 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 May 2014 15:52:15 +0530 Subject: [PATCH] Get rid of install command line tool, since Apple has deprecated the API's it used to obtain root --- manual/creating_plugins.rst | 6 +- manual/custom.py | 7 ++- manual/news.rst | 5 +- src/calibre/gui2/preferences/misc.py | 21 +------ src/calibre/gui2/preferences/misc.ui | 17 ++--- src/calibre/utils/osx_symlinks.py | 93 ---------------------------- 6 files changed, 17 insertions(+), 132 deletions(-) delete mode 100644 src/calibre/utils/osx_symlinks.py diff --git a/manual/creating_plugins.rst b/manual/creating_plugins.rst index c813039dfd..c52b674162 100644 --- a/manual/creating_plugins.rst +++ b/manual/creating_plugins.rst @@ -38,9 +38,9 @@ the directory in which you created :file:`__init__.py`:: calibre-customize -b . .. note:: - On OS X you have to first install the |app| command line tools, by - going to :guilabel:`Preferences->Miscellaneous` and clicking the - :guilabel:`Install command line tools` button. + On OS X, the command line tools are inside the |app| bundle, for example, + if you installed calibre in :file:`/Applications` the command line tools + are in :file:`/Applications/calibre.app/Contents/MacOS/calibre`. You can download the Hello World plugin from `helloworld_plugin.zip `_. diff --git a/manual/custom.py b/manual/custom.py index feb3c03c7c..650c460854 100644 --- a/manual/custom.py +++ b/manual/custom.py @@ -29,9 +29,10 @@ Command Line Interface .. image:: ../images/cli.png -On OS X you have to go to Preferences->Advanced->Miscellaneous and click install command line -tools to make the command line tools available. On other platforms, just start -a terminal and type the command. +.. note:: + On OS X, the command line tools are inside the |app| bundle, for example, + if you installed calibre in :file:`/Applications` the command line tools + are in :file:`/Applications/calibre.app/Contents/MacOS/calibre`. Documented Commands -------------------- diff --git a/manual/news.rst b/manual/news.rst index 21b8b592ab..84b5a0c68a 100755 --- a/manual/news.rst +++ b/manual/news.rst @@ -295,7 +295,10 @@ Once the download is complete, you can look at the downloaded :term:`HTML` by op If you're satisfied with your recipe, and you feel there is enough demand to justify its inclusion into the set of built-in recipes, post your recipe in the `calibre recipes forum `_ to share it with other calibre users. -.. note:: On OS X, the ebook-convert command will not be available by default. Go to Preferences->Miscellaneous and click the install command line tools button to make it available. +.. note:: + On OS X, the command line tools are inside the |app| bundle, for example, + if you installed calibre in :file:`/Applications` the command line tools + are in :file:`/Applications/calibre.app/Contents/MacOS/calibre`. .. seealso:: diff --git a/src/calibre/gui2/preferences/misc.py b/src/calibre/gui2/preferences/misc.py index c4e8c92a43..1052430f8a 100644 --- a/src/calibre/gui2/preferences/misc.py +++ b/src/calibre/gui2/preferences/misc.py @@ -9,9 +9,7 @@ import textwrap from calibre.gui2.preferences import ConfigWidgetBase, test_widget, Setting from calibre.gui2.preferences.misc_ui import Ui_Form -from calibre.gui2 import (error_dialog, config, open_local_file, info_dialog, - gprefs) -from calibre.constants import isosx +from calibre.gui2 import (config, open_local_file, gprefs) from calibre import get_proxies class WorkersSetting(Setting): @@ -40,8 +38,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.device_detection_button.clicked.connect(self.debug_device_detection) self.button_open_config_dir.clicked.connect(self.open_config_dir) self.user_defined_device_button.clicked.connect(self.user_defined_device) - self.button_osx_symlinks.clicked.connect(self.create_symlinks) - self.button_osx_symlinks.setVisible(isosx) proxies = get_proxies(debug=False) txt = _('No proxies used') if proxies: @@ -64,21 +60,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): from calibre.utils.config import config_dir open_local_file(config_dir) - def create_symlinks(self): - from calibre.utils.osx_symlinks import create_symlinks - loc, paths = create_symlinks() - if loc is None: - error_dialog(self, _('Error'), - _('Failed to install command line tools.'), - det_msg=paths, show=True) - else: - info_dialog(self, _('Command line tools installed'), - '

'+_('Command line tools installed in')+' '+loc+ - '
'+ _('If you move calibre.app, you have to re-install ' - 'the command line tools.'), - det_msg='\n'.join(paths), show=True) - - if __name__ == '__main__': from PyQt5.Qt import QApplication app = QApplication([]) diff --git a/src/calibre/gui2/preferences/misc.ui b/src/calibre/gui2/preferences/misc.ui index 1b4f0a1658..73fe45e10d 100644 --- a/src/calibre/gui2/preferences/misc.ui +++ b/src/calibre/gui2/preferences/misc.ui @@ -91,13 +91,6 @@ - - - - Open calibre &configuration directory - - - @@ -111,14 +104,14 @@ - - + + - &Install command line tools + Open calibre &configuration directory - + Qt::Vertical @@ -131,7 +124,7 @@ - + diff --git a/src/calibre/utils/osx_symlinks.py b/src/calibre/utils/osx_symlinks.py deleted file mode 100644 index ef2d39dea9..0000000000 --- a/src/calibre/utils/osx_symlinks.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement - -__license__ = 'GPL v3' -__copyright__ = '2009, Kovid Goyal ' -__docformat__ = 'restructuredtext en' - -import sys, os, cPickle -from calibre.constants import isnewosx - -AUTHTOOL="""#!/usr/bin/python -import os -scripts = %s -links = %s -os.setuid(0) -for s, l in zip(scripts, links): - try: - os.remove(l) - except: - pass - print 'Creating link:', l, '->', s - omask = os.umask(022) - os.symlink(s, l) - os.umask(omask) -""" - -DEST_PATH = '/usr/bin' - -def create_symlinks(): - return create_symlinks_new() if isnewosx else create_symlinks_old() - -def get_scripts(): - return cPickle.load(open(P('scripts.pickle'), 'rb')) - -def create_symlinks_new(): - scripts = get_scripts() - - links = [os.path.join(DEST_PATH, i) for i in scripts] - scripts = [os.path.join( - sys.binaries_path if scripts[i] == 'gui' else sys.console_binaries_path, i) for i in scripts] - - return do_it(scripts, links) - - -def create_symlinks_old(): - scripts = get_scripts() - - resources_path = os.environ['RESOURCEPATH'] - links = [os.path.join(DEST_PATH, i) for i in scripts] - scripts = [os.path.join(resources_path, 'loaders', i) for i in scripts] - - return do_it(scripts, links) - -def do_it(scripts, links): - import os, tempfile, traceback - from Authorization import Authorization, kAuthorizationFlagDestroyRights - r1, r2 = DEST_PATH, links - bad = False - for s, l in zip(scripts, links): - if os.path.exists(l) and os.path.exists(os.path.realpath(l)): - continue - bad = True - break - if bad: - ph, pp = os.environ.get('PYTHONHOME', None), os.environ.get('PYTHONPATH', None) - auth = Authorization(destroyflags=(kAuthorizationFlagDestroyRights,)) - fd, name = tempfile.mkstemp('.py') - os.write(fd, AUTHTOOL % (repr(scripts), repr(links))) - os.close(fd) - os.chmod(name, 0700) - try: - if pp: - del os.environ['PYTHONPATH'] - if ph: - del os.environ['PYTHONHOME'] - pipe = auth.executeWithPrivileges(name) - try: - sys.stdout.write(pipe.read()) - except: - sys.stdout.write(pipe.read()) # Probably EINTR - pipe.close() - except: - r1, r2 = None, traceback.format_exc() - finally: - os.unlink(name) - if pp: - os.environ['PYTHONPATH'] = pp - if ph: - os.environ['PYTHONHOME'] = ph - - return r1, r2 -