pywikibot-catfiles / file-metadata

A python package to analyze files and provide useful metadata
MIT License
15 stars 1 forks source link

Add more install info to error messages #46

Closed drtrigon closed 8 years ago

drtrigon commented 8 years ago

Running the test bot script gave me a very nice error message, see below - well done!

$ python file_metadata_bot.py -cat:SVG_files -limit:5
Retrieving 5 pages from commons:commons.
Traceback (most recent call last):
  File "file_metadata_bot.py", line 103, in <module>
    main(*sys.argv)
  File "file_metadata_bot.py", line 97, in main
    log = handle_page(page)
  File "file_metadata_bot.py", line 66, in handle_page
    _file = GenericFile.create(file_path)
  File "/usr/local/lib/python2.7/dist-packages/file_metadata/generic_file.py", line 76, in create
    return ImageFile.create(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/file_metadata/image/image_file.py", line 56, in create
    from file_metadata.image.svg_file import SVGFile
  File "/usr/local/lib/python2.7/dist-packages/file_metadata/image/svg_file.py", line 9, in <module>
    import wand.image
  File "/usr/local/lib/python2.7/dist-packages/wand/image.py", line 20, in <module>
    from .api import MagickPixelPacket, libc, libmagick, library
  File "/usr/local/lib/python2.7/dist-packages/wand/api.py", line 206, in <module>
    'Try to install:\n  ' + msg)
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
  apt-get install libmagickwand-dev
<type 'exceptions.ImportError'>
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort

However I would like to mention to add also info for fedora distributions (yum) and may be others (osx, later win) so we should have this in manner easily adoptable - e.g. a dict at the beginning of a file or even a own file (like i18n e.g.).

AbdealiLoKo commented 8 years ago

So, the people over at wand give the error message related to the system only. i.e. if youre on Ubuntu/Debian they don't show yum. The relevant code is in their repo.

drtrigon commented 8 years ago

I like that! We need similar messages in our part of the code.

As mentioned in https://phabricator.wikimedia.org/T138121#2407656, IMHO there is a need for a final solution but I do not think this should be part of the current project. So I would say 'externals' has to come back in some way combined with the other approaches out there, but that something for the future... ;)

https://gist.github.com/drtrigon/7231d760b26d8ea1370b35929da05f58

AbdealiLoKo commented 8 years ago

I've made a modification to the codebase now, which would give error messages like this if installation fails:

(py27) [ajk@localhost file-metadata]$ pip install -e .
Obtaining file:///home/ajk/Documents/wiki/file-metadata
    Complete output from command python setup.py egg_info:
    Check and install dependencies required for setup:
    distro - Will be installed with pip.
    setuptools - Will be installed with pip.
    Check dependencies required for using file-metadata:
    libmagic - Found "file" utility at /usr/bin/file.
    python-magic - Will be installed with pip.
    six - Will be installed with pip.
    exiftool - Needs to be installed manually.
    appdirs - Will be installed with pip.
    pathlib - Backported pathlib2 will be installed with pip.
    liblzma - Found with pkg-config.
    lzma - Will install backports.lzma with pip.
    pillow - Will be installed with pip.
    setuptools - numpy - Will be installed with pip.
    dlib - Will be installed with pip.
    scikit-image - Will be installed with pip.
    magickwand - Needs to be installed manually.
    wand - Will be installed with pip.
    libzbar - Found libzbar.so.0.
    zbar - Will be installed with pip.
    java - Found at /usr/bin/java.
    pycolorname - Will be installed with pip.
    ffprobe - Needs to be installed manually.
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/ajk/Documents/wiki/file-metadata/setup.py", line 100, in <module>
        install_required = get_install_requires(install_deps)
      File "/home/ajk/Documents/wiki/file-metadata/setup.py", line 70, in get_install_requires
        for dep in check_deps(deplist):
      File "/home/ajk/Documents/wiki/file-metadata/setup.py", line 64, in check_deps
        raise DistutilsSetupError(msg)
    distutils.errors.DistutilsSetupError: Some dependencies could not be installed automatically: exiftool, boost-python, magickwand, ffprobe
    * Try installing exiftool with `dnf install perl-Image-ExifTool`
    * Try installing boost-python with `dnf install boost-python`
    * Try installing magickwand with `dnf install ImageMagick-devel`
    * Try installing ffprobe with `dnf install ffmpeg`. Note: This requires the RPMFusion repo to be enabled.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /home/ajk/Documents/wiki/file-metadata/
drtrigon commented 8 years ago

That look very nice!! I like it!

Next step ask the user whether it should be done for convenience and then ask for permission to execute the command. That could be done using e.g. invoke.

Dr. Trigon