Commit Graph

13 Commits

Author SHA1 Message Date
Gerald Combs 30c392f166 Tools+test: Call python3 explicitly.
PEP 394[1] says,

"In cases where the script is expected to be executed outside virtual
 environments, developers will need to be aware of the following
 discrepancies across platforms and installation methods:

  * Older Linux distributions will provide a python command that refers
    to Python 2, and will likely not provide a python2 command.

  * Some newer Linux distributions will provide a python command that
    refers to Python 3.

  * Some Linux distributions will not provide a python command at all by
    default, but will provide a python3 command by default."

Debian has forced the issue by choosing the third option[2]:

"NOTE: Debian testing (bullseye) has removed the "python" package and
 the '/usr/bin/python' symlink due to the deprecation of Python 2."

Switch our shebang from "#!/usr/bin/env python" to "#!/usr/bin/env
python3" in some places. Remove some 2/3 version checks if we know we're
running under Python 3. Remove the "coding: utf-8" in a bunch of places
since that's the default in Python 3.

[1]https://www.python.org/dev/peps/pep-0394/#for-python-script-publishers
[2]https://wiki.debian.org/Python
2020-11-05 06:46:35 +00:00
Jeff Widman 8d7ebc732e Fix issues discovered by common python linters
Fix some issues discovered by common python linters including:
* switch `None` comparisons to use `is` rather than `==`. Identity !=
equality, and I've spent 40+ hours before tracking down a subtle bug
caused by exactly this issue. Note that this may introduce a problem if
one of the scripts is depending on this behavior, in which case the
comparison should be changed to `True`/`False` rather than `None`.
* Use `except Exception:` as bare `except:` statements have been
discouraged for years. Ideally for some of these we'd examine if there
were specific exceptions that should be caught, but for now I simply
caught all. Again, this could introduce very subtle behavioral changes
under Python 2, but IIUC, that was all fixed in Python 3, so safe to
move to `except Exception:`.
* Use more idiomatic `if not x in y`--> `if x not in y`
* Use more idiomatic 2 blank lines. I only did this at the beginning,
until I realized how overwhelming this was going to be to apply, then I
stopped.
* Add a TODO where an undefined function name is called, so will fail
whenever that code is run.
* Add more idiomatic spacing around `:`. This is also only partially
cleaned up, as I gave up when I saw how `asn2wrs.py` was clearly
infatuated with the construct.
* Various other small cleanups, removed some trailing whitespace and
improper indentation that wasn't a multiple of 4, etc.

There is still _much_ to do, but I haven't been heavily involved with
this project before, so thought this was a sufficient amount to put up
and see what the feedback is.

Linters that I have enabled which highlighted some of these issues
include:
* `pylint`
* `flake8`
* `pycodestyle`
2020-09-26 04:38:18 +00:00
Gerald Combs 31414484d4 html2text: Skip generating footnotes for self-links.
Fixes the issue described at
https://www.wireshark.org/lists/wireshark-users/201912/msg00003.html

Change-Id: Ie3fd338ab1c6b216b05eeca002545868d3474bbb
Reviewed-on: https://code.wireshark.org/review/35426
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-12-13 05:29:54 +00:00
Gerald Combs 403f556c30 html2text: Fix our footnotes.
Print <number>: <url> instead of <number>: <number>.

Change-Id: I55fd668c8d5870dbd43868e91f9299d5d5580b3f
Reviewed-on: https://code.wireshark.org/review/32048
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2019-02-15 20:53:00 +00:00
Matej Tkac f8ac12c5b3 html2txt.py: replaced 2 occurences of '{}' with equal '{0}' because of CentOS 6.x+Python2.6.6 issues
Change-Id: Ibf395007e32db70f49b7bdae22fff8c377ae41b0
Reviewed-on: https://code.wireshark.org/review/27457
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-05-12 19:54:05 +00:00
Gerald Combs 4bff0e6dd1 html2text: Wrap at 72 characters.
Change-Id: Id8c9d74b71cabce6bbfb25fd857f71c4b2a4e8ea
Reviewed-on: https://code.wireshark.org/review/26556
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-20 15:46:08 +00:00
Dario Lombardo 8a5385b9c9 More licenses converted to SPDX.
Change-Id: Id4f987dcdacf06622d70263f4659a4400e30dc39
Reviewed-on: https://code.wireshark.org/review/26332
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-03-07 13:35:49 +00:00
Gerald Combs 045c48e81e html2text: Prefix lists with a bullet.
Prefix lists with a bullet symbol (U+2022) instead on an asterisk.

Skip the <head> tag while we're here so that we don't print the title
twice.

Change-Id: I1dfad1fc70aa05319e14c55b663dd2183ab87d79
Reviewed-on: https://code.wireshark.org/review/25762
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-02-12 23:35:00 +00:00
Gerald Combs b511312633 html2text: Skip some tags and add references.
Skip the contents of <style> and <script> tags. Add URL footnotes
similar to `lynx -dump`.

Change-Id: I721bdfabeacc000d604aa8475f13be1d797ad0fb
Reviewed-on: https://code.wireshark.org/review/25697
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-09 05:30:14 +00:00
Peter Wu 13c486c33f html2text.py: Python 2.5 compatibility, improve Unicode support
Add support for Python 2.5 (remove unicode_literals import which does
not seem to be necessary), check before using break_on_hyphens (without
this option in Python 2.5, the output is uglier though) and avoid the
'with' keyword.

While at it, fix reading Unicode text from file in Python 2 (tested
with: echo € | tools/html2text.py) and support reading from stdin using
the '-' filename.

Tested against Python 2.5.6, 2.6.6, 2.7.9, 3.2.6, 3.4.3 with the
commands from the previous html2text.py commit message, and additionally
with the Unicode character € as input (instead of the faq.py output).

Change-Id: I3de3f7a4e7cf7d702463c3a59758803843338a54
Reviewed-on: https://code.wireshark.org/review/7823
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-03-26 07:14:20 +00:00
Peter Wu 68698db8cc Always use html2text.py for FAQ, improve output
A recent commit broke compilation with Python 3. The original author of
html2text.py is deceased and the fork has increased the number of files
for this "simple" helper.

The html2text.py script in this patch was rewritten and its output
matches with lynx (except for a few newlines around lists). This means
that indentation has been added for headings, paragraphs and lists.
Also, since it was written from scratch, a new license could be chosen
that matches Wireshark.

Since now the in-tree html2text.py script provides nicer output, remove
detection of the alternative programs (elinks, links). lynx/w3m is
somehow still necessary for asciidoc though.

(I also looked into reusing html2text.py for the release notes to
replace asciidoc, but the --format=html output produces different output
(HTML adds a ToC and section numbers). For now still require lynx for
release notes)

Tested with Python 2.6.6, 2.7.9, 3.2.6 and 3.4.3 under LC_ALL=C and
LC_ALL=en_US.UTF-8 on Linux. Tested reading from stdin and file, writing
to file, pipe and tty. Tested with cmake (Ninja) and autotools on Arch
Linux x86_64. Test:

    # For each $PATH per python version, execute (with varying LC_ALL)
    help/faq.py -b | tools/html2text.py /dev/stdin | md5sum
    help/faq.py -b | tools/html2text.py | md5sum
    help/faq.py -b | tools/html2text.py
    help/faq.py -b | tools/html2text.py >/dev/null

Change-Id: I6409450a3e6c8b010ca082251f9db7358b0cc2fd
Reviewed-on: https://code.wireshark.org/review/7779
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-03-25 07:08:52 +00:00
Gerald Combs f49377e0e7 Update html2text.py to suit our needs. Add spaces in the faq.txt target
so to fix a problem with OS X 10.4. Add html2text.py to the end of the
faq.txt target.

svn path=/trunk/; revision=27040
2008-12-17 19:49:18 +00:00
Gerald Combs 79413d1f89 Add html2text.py 2.35 from http://www.aaronsw.com/2002/html2text/.
svn path=/trunk/; revision=27039
2008-12-17 19:41:43 +00:00