Difference between revisions of "User:Alvonruff/Python3 Files"

From ISFDB
Jump to navigation Jump to search
Line 9: Line 9:
 
* While most SQL code is in SQLparsing.py, it is also peppered across many other files. This code will not work any longer, as Python3 requires moving to a new connector. I've created an ISFDB connector class which is portable across Python2 and Python3. Some usage patterns are:
 
* While most SQL code is in SQLparsing.py, it is also peppered across many other files. This code will not work any longer, as Python3 requires moving to a new connector. I've created an ISFDB connector class which is portable across Python2 and Python3. Some usage patterns are:
  
 +
FETCHMANY:
 
     def _StandardQuery(query):
 
     def _StandardQuery(query):
 
         CNX = MYSQL_CONNECTOR()
 
         CNX = MYSQL_CONNECTOR()
Line 19: Line 20:
 
         return results
 
         return results
  
 +
NUMROWS:
 
     def _BinaryQuery(query):
 
     def _BinaryQuery(query):
 
         CNX = MYSQL_CONNECTOR()
 
         CNX = MYSQL_CONNECTOR()
Line 27: Line 29:
 
                 return 0
 
                 return 0
  
 +
FETCHONE:
 
     def _OneRow(query):
 
     def _OneRow(query):
 
         CNX = MYSQL_CONNECTOR()
 
         CNX = MYSQL_CONNECTOR()
Line 36: Line 39:
 
                 return None
 
                 return None
  
 +
DB_ESCAPE_STRING:
 
     def SQLgetAuthorData(author):
 
     def SQLgetAuthorData(author):
 
         CNX = MYSQL_CONNECTOR()
 
         CNX = MYSQL_CONNECTOR()
Line 45: Line 49:
 
         else:
 
         else:
 
                 return 0
 
                 return 0
 +
 +
DB_INSERT_ID:
 +
        CNX = MYSQL_CONNECTOR()
 +
        query = "insert into titles(title_title) values('%s');" % (CNX.DB_ESCAPE_STRING(title))
 +
        CNX.DB_QUERY(query)
 +
        record = DB_INSERT_ID()
  
 
* We also need to remove all of the stray '''import MySQLdb''' statements. MySQLdb is imported by SQLparsing under Python2, and causes an error on Python3.
 
* We also need to remove all of the stray '''import MySQLdb''' statements. MySQLdb is imported by SQLparsing under Python2, and causes an error on Python3.

Revision as of 08:39, 22 May 2023

This page tracks changes that can be made and still run under Python2.

This page tracks changes that can be made for Python3 that also run fine under Python2. The changes are:

  • Replacing tabs with 8 spaces. Almost every file attempted so far has some mix of spaces and tabs. In vi/vim this can be changed with:
   :s/<tab>/<8 spaces>/g
  • Change all print statements to use function call syntax. This can be done by 2to3 (a variant of futurize). 2to3 without arguments will make many python3 changes, but it also takes a -f argument, which allows you to attack one specific problem. To use, create a target directory (like FUTURIZE), and issuing the following command:
   2to3 awardClass.py -f print -n -w -o FUTURIZE
  • Change all instance of string.method to str.method.
  • While most SQL code is in SQLparsing.py, it is also peppered across many other files. This code will not work any longer, as Python3 requires moving to a new connector. I've created an ISFDB connector class which is portable across Python2 and Python3. Some usage patterns are:

FETCHMANY:

   def _StandardQuery(query):
       CNX = MYSQL_CONNECTOR()
       CNX.DB_QUERY(query)
       results = []
       record = CNX.DB_FETCHMANY()
       while record:
               results.append(record[0])
               record = CNX.DB_FETCHMANY()
       return results

NUMROWS:

   def _BinaryQuery(query):
       CNX = MYSQL_CONNECTOR()
       CNX.DB_QUERY(query)
       if CNX.DB_NUMROWS():
               return 1
       else:
               return 0

FETCHONE:

   def _OneRow(query):
       CNX = MYSQL_CONNECTOR()
       CNX.DB_QUERY(query)
       record = CNX.DB_FETCHONE()
       if record:
               return record[0]
       else:
               return None

DB_ESCAPE_STRING:

   def SQLgetAuthorData(author):
       CNX = MYSQL_CONNECTOR()
       query = "select %s from authors where author_canonical='%s'" % (CNX_AUTHORS_STAR, CNX.DB_ESCAPE_STRING(author))
       CNX.DB_QUERY(query)
       record = CNX.DB_FETCHONE()
       if record:
               return record[0]
       else:
               return 0

DB_INSERT_ID:

       CNX = MYSQL_CONNECTOR()
       query = "insert into titles(title_title) values('%s');" % (CNX.DB_ESCAPE_STRING(title))
       CNX.DB_QUERY(query)
       record = DB_INSERT_ID()
  • We also need to remove all of the stray import MySQLdb statements. MySQLdb is imported by SQLparsing under Python2, and causes an error on Python3.

Common

File Tabs Print String DB Connector
authorClass.py Y Y Y Y
awardcatClass.py Y Y Y Y
awardClass.py Y Y Y Y
awardtypeClass.py Y Y Y Y
install.py Y Y Y -
isbn.py Y Y Y Y
isfdblib.py - - - -
isfdb.py Y Y Y Y
library.py Y Y Y Y
localdefs.py - - - -
login.py Y Y Y Y
navbar.py Y Y Y Y
pubClass.py Y Y Y Y
publisherClass.py Y Y Y Y
pubseriesClass.py Y Y Y Y
seriesClass.py Y Y Y Y
sfe3.py Y Y Y Y
SQLparsing.py Y Y Y Y
templateClass.py Y Y Y Y
titleClass.py Y Y Y Y
verificationsourceClass.py Y Y Y Y
viewers.py Y Y Y Y

Biblio

File Tabs Print String DB Connector
adv_identifier_search.py Y Y Y Y
adv_notes_search.py Y Y Y Y
advSearchClass.py Y Y Y Y
adv_search_menu.py Y Y Y Y
adv_search_results.py Y Y Y Y
adv_search_selection.py Y Y Y Y
adv_user_search.py Y Y Y Y
adv_web_page_search.py Y Y Y Y
ae.py Y Y Y Y
author_history.py Y Y Y Y
authors_by_debut_year.py Y Y Y Y
authors_by_debut_year_table.py Y Y Y Y
authortags.py Y Y Y Y
award_category_history.py Y Y Y Y
award_category.py Y Y Y Y
award_category_year.py Y Y Y Y
award_details.py Y Y Y Y
award_directory.py Y Y Y Y
award_history.py Y Y Y Y
awardtype_history.py Y Y Y Y
awardtype.py Y Y Y Y
ay.py Y Y Y Y
biblio.py Y Y Y Y
calendarClass.py Y Y Y Y
calendar_day.py Y Y Y Y
calendar_menu.py Y Y Y Y
cancelsubmission.py Y Y Y Y
changed_verified_pubs.py Y Y Y Y
ch.py Y Y Y Y
common.py Y Y Y Y
diffselect.py Y Y Y Y
directory.py Y Y Y Y
dologin.py Y Y Y Y
dologout.py Y Y Y Y
dumpxml.py Y Y Y Y
ea.py Y Y Y Y
eaw.py Y Y Y Y
external_id_search_results.py Y Y Y Y
fc.py Y Y Y Y
google_search_redirect.py Y Y Y Y
index.py Y Y Y Y
languages.py Y Y Y Y
most_popular.py Y Y Y Y
most_popular_table.py Y Y Y Y
most_reviewed.py Y Y Y Y
most_reviewed_table.py Y Y Y Y
mylanguages.py Y Y Y Y
mypreferences.py Y Y Y Y
myrecent.py Y Y Y Y
my_removed_secondary_verifications.py Y Y Y Y
my_secondary_verifications.py Y Y Y Y
my_unstable_ISBN_verifications.py Y Y Y Y
my_unstable_verifications.py Y Y Y Y
myverificationsClass.py Y Y Y Y
my_verifications_menu.py Y Y Y Y
myvotes.py Y Y Y Y
mywebsites.py Y Y Y Y
note.py Y Y Y Y
note_search_results.py Y Y Y Y
pe.py Y Y Y Y
pl.py Y Y Y Y
popular_authors.py Y Y Y Y
popular_authors_table.py Y Y Y Y
pub_history.py Y Y Y Y
publisher_authors.py Y Y Y Y
publisher_history.py Y Y Y Y
publisher_one_author.py Y Y Y Y
publisher.py Y Y Y Y
publisheryear.py Y Y Y Y
pubseries_history.py Y Y Y Y
pubseries.py Y Y Y Y
pubs_not_in_series.py Y Y Y Y
recent_activity_menu.py Y Y Y Y
recent_primary_ver.py Y Y Y Y
recent.py Y Y Y Y
recentver.py Y Y Y Y
removed_secondary_verifications.py Y Y Y Y
se.py Y Y Y Y
seriesgrid.py Y Y Y Y
series_history.py Y Y Y Y
seriestags.py Y Y Y Y
stats-and-tops.py Y Y Y Y
stats.py Y Y Y Y
submitdiff.py Y Y Y Y
submitlogin.py Y Y Y Y
submitmylanguages.py Y Y Y Y
submitmywebsites.py Y Y Y Y
submitpreferences.py Y Y Y Y
tag_author.py Y Y Y Y
tag.py Y Y Y Y
titlecovers.py Y Y Y Y
title_history.py Y Y Y Y
title.py Y Y Y Y
topcontrib.py Y Y Y Y
user_search_results.py Y Y Y Y
usertag.py Y Y Y Y
usertitles.py Y Y Y Y
userver.py Y Y Y Y
utils.py Y Y Y Y
verification_sources.py Y Y Y Y
view_submission.py Y Y Y Y
webpages_search_results.py Y Y Y Y

Edit

File Tabs Print String DB Connector
addawardcat.py Y Y Y Y
addaward.py Y Y Y Y
addpub.py Y Y Y Y
addquicktag.py Y Y Y Y
add_template.py Y Y Y Y
addvariant.py Y Y Y Y
add_verification_source.py Y Y Y Y
as_merge.py Y Y Y Y
av_merge.py Y Y Y Y
cleanup_lib.py
cleanup.py
cleanup_report.py
clonecontent.py Y Y Y Y
clone_intermediate.py Y Y Y Y
clonepub.py Y Y Y Y
deleteawardcat.py
deleteaward.py
deleteawardtype.py Y Y Y Y
deletepub.py
deleteseries.py
deletetitle.py Y Y Y Y
editauth.py Y Y Y Y
editawardcat.py
editaward.py Y Y Y Y
editawardtype.py Y Y Y Y
editpublisher.py
editpub.py Y Y Y Y
editpubseries.py
editseries.py
edittags.py
edit_template.py
edittitle.py Y Y Y Y
edit_verification_source.py
empty_containers.py
exportcontent.py Y Y Y Y
find_dups.py Y Y Y Y
find_pub_dups.py Y Y Y Y
find_title_dups.py Y Y Y Y
importcontent.py Y Y Y Y
incomplete_contents.py
isfdblib.py Y Y Y Y
isfdblib_help.py
isfdblib_print.py Y Y Y Y
keygen.py
linkaward.py
linkreview.py
login.py Y Y Y Y
mkpseudo.py Y Y Y Y
mkvariant.py
newawardtype.py
new_language.py
newpub.py
numeric_external_id_ranges.py
ps_merge.py
publisher_exceptions.py
pv_merge.py
rmtitles.py Y Y Y Y
select_award_type.py Y Y Y Y
sfe3_authors.py
submitaddpub.py Y Y Y Y
submit_add_template.py Y Y Y Y
submit_add_verification_source.py Y Y Y Y
submitauth.py Y Y Y Y
submitawardcat.py
submitaward.py Y Y Y Y
submitawardtype.py Y Y Y Y
submitclone.py Y Y Y Y
submitdelaward.py
submitdeleteawardcat.py
submitdeleteawardtype.py
submitdelpub.py
submitdelseries.py
submitdeltitle.py
submit_edit_template.py
submit_edit_verification_source.py
submitlinkaward.py
submitlinkreview.py
submitmkpseudo.py Y Y Y Y
submitmkvar1.py
submitmkvar2.py
submitnewawardcat.py Y Y Y Y
submitnewaward.py Y Y Y Y
submitnewawardtype.py
submit_new_language.py
submitnewpub.py
submit_primary_verification.py
submitpublisher.py
submitpub.py Y Y Y Y
submitpubseries.py
submitrempseudo.py
submitrm.py Y Y Y Y
submit_select_award_type.py Y Y Y Y
submitseries.py
submittags.py
submittitle.py Y Y Y Y
submitvariant.py Y Y Y Y
submitver.py
submitvote.py
ts_merge.py
ts_unmerge.py Y Y Y Y
tv_merge.py
tv_unmerge.py Y Y Y Y
verify.py
vote.py

Mod

aa_merge.py aa_update.py award_cat_delete_file.py award_cat_new_file.py award_cat_update_file.py award_link_file.py awardtypeClass.py award_type_delete_file.py award_type_new_file.py award_type_update_file.py bad_images.py bureaucrat.py ca_new.py change_tag_status.py common.py cpanel.py hardreject.py hold.py isfdblib.py Y isfdb.py ka_new.py library.py list.py list_templates.py list_verification_sources.py local localdefs.py local.mk login.py marque.py navbar.py new_language_file.py pa_delete.py pa_new.py pa_update.py private_tags.py pubClass.py publisherClass.py pubseriesClass.py ra_link.py recent.py reject.py remove_secondary_verification.py remove_tag.py resolve_bad_url.py resolve_cleanup.py resolve_empty_containers.py resolve_sfe3_url.py sa_delete.py sa_update.py select_secondary_verification.py self_approver_file.py self_approvers.py seriesClass.py sfe3.py SQLparsing.py submission_review.py submission_search.py submission_search_results.py submitcpanel.py submitref.py ta_delete.py tag_breakdown.py tag_status_changes.py ta_merge.py ta_remove.py ta_unmerge.py ta_update.py template_add_file.py templateClass.py template_update_file.py titleClass.py ua_merge.py unhold.py unreject.py va_new.py verification_source_add_file.py verificationsourceClass.py verification_source_file.py viewers.py wa_delete.py wa_new.py wa_update.py xa_update.py ya_new.py ya_remove.py za_update.py
File Tabs Print String

Rest

File Tabs Print String