User:Alvonruff/Python2.7 Futurize

From ISFDB
< User:Alvonruff
Revision as of 07:20, 15 September 2022 by Alvonruff (talk | contribs)
Jump to navigation Jump to search

Prerequisites

  • pip2 install future
  • pip2 install six

Conversion

  • Within the target directory (biblio, common, edit, etc), create a new directory called FUTURIZE
  • Create a shell script which lists all py files in the target directory, and turn it into a futurize command as shown below. This will create a modified version of the file in the local FUTURIZE directory.
   set -x
   futurize adv_identifier_search.py -n -w -o FUTURIZE
   futurize adv_notes_search.py -n -w -o FUTURIZE
   futurize advSearchClass.py -n -w -o FUTURIZE
   futurize adv_search_menu.py -n -w -o FUTURIZE
   futurize adv_search_results.py -n -w -o FUTURIZE
   ...
  • Edit each of the output files, and move any import lines of the form "from __future__ import xxx" below the top comment block. The first line of the comment block contains the poundbang statement, which tells the OS that it should use python to interpret the file. The poundbang statement must be the first line of the file, but futurize will place some of the import statements before the poundbang, causing a runtime error.
  • You are now free to replace specific files within the target directory with its futurized version. You may want to keep a directory containing original versions of the files, so that you may revert to its original state if some disaster ensues.

Issues

Pound Pricing

Issue: When printing publication details, an exception occurs whenever the pricing is in British Pounds. It's curious that the publication note can have information utilizing the Pound symbol, but the Price field fails.

Example: https://www.isfdb2.org/cgi-bin/p3/pl.cgi?911384

Workaround: At the beginning of ISFDBPrice (common/library.py) place:

   price = price.decode('utf8', 'ignore')

This merely allows the script to complete, as it does not output a Pound symbol. Need to find the real fix.