removed dependency to python-magic

This commit is contained in:
Lionel Dricot 2022-03-29 22:08:30 +02:00
parent 007076ab0a
commit 5207164d3c
4 changed files with 15 additions and 18 deletions

View File

@ -1,7 +1,8 @@
# Offpunk History
## 1.3 - Unreleased
- Removed dependency to python editor. If no $VISUAL or $EDITOR, please use "set editor" in Offpunk.
- Removed dependency to python-magic. File is now used directly (and should be on every system).
- Removed dependency to python-editor. If no $VISUAL or $EDITOR, please use "set editor" in Offpunk.
- New behaviour for "find" (or "/") which is to grep through current page (ripgrep used if detected)
- Default width set to 80 as many gopherholes and gemini capsules have it hardcoded
- Streaming URL without valid content-length are now closed after 5Mo of download (thanks to Eoin Carney for reporting the issue)

View File

@ -76,12 +76,12 @@ To avoid using unstable or too recent libraries, the rule of thumb is that a lib
Run command `version` in offpunk to see if you are missing some dependencies.
Highly recommended:
Highly recommended (packagers should probably make those mandatory):
* [xdg-utils](https://www.freedesktop.org/wiki/Software/xdg-utils/) provides xdg-open which is highly recommended to open files without a renderer or a handler. It is also used for mailto: command.
* The [cryptography library](https://pypi.org/project/cryptography/) will provide a better and slightly more secure experience when using the default TOFU certificate validation mode and is highly recommended (apt-get install python3-cryptography).
* [Python magic](https://github.com/ahupp/python-magic/) is useful to determine the MIME type of cached object. If not present, the file extension will be used but some capsules provide wrong extension or no extension at all. Python-magic is highly recommended. (apt-get install python3-magic)
* [file](https://www.darwinsys.com/file/) is used to get the MIME type of cached objects. But it should already be on your system.
Dependencies to enable web browsing.
Dependencies to enable web browsing (packagers should put those in an offpunk-web meta-package)
* [Python-requests](http://python-requests.org) is needed to handle http/https requests natively (apt-get install python3-requests). Without it, http links will be opened in an external browser
* [BeautifulSoup4](https://www.crummy.com/software/BeautifulSoup) and [Readability](https://github.com/buriy/python-readability) are both needed to render HTML. Without them, HTML will not be rendered or be sent to an external parser like Lynx. (apt-get install python3-bs4 python3-readability or pip3 install readability-lxml)
* [Python-feedparser](https://github.com/kurtmckee/feedparser) will allow parsing of RSS/Atom feeds and thus subscriptions to them. (apt-get install python3-feedparser)
@ -89,7 +89,7 @@ Dependencies to enable web browsing.
* [Timg](https://github.com/hzeller/timg) is a slower alternative to chafa for inline images. But it has better rendering when displaying only the image. Install both to get the best of both world but if you need to choose one, choose Chafa.
* [Python-pil](http://python-pillow.github.io/) is required to only display the first frame of animated gif with chafa if chafa version is lower than 1.10.
Nice to have:
Nice to have (packagers should probaly make those optional):
* [Xsel](http://www.vergenet.net/~conrad/software/xsel/) allows to `go` to the URL copied in the clipboard without having to paste it (both X and traditional clipboards are supported). Also needed to use the `copy` command. (apt-get install xsel)
* [Python-setproctitle](https://github.com/dvarrazzo/py-setproctitle) will change the process name from "python" to "offpunk". Useful to kill it without killing every python service.
* [RipGrep](https://github.com/BurntSushi/ripgrep) is used, if found, to add colours to your in-page searches ("find" or "/").

View File

@ -144,13 +144,6 @@ try:
except ModuleNotFoundError:
_HAS_CRYPTOGRAPHY = False
try:
import magic
_HAS_MAGIC = True
except ModuleNotFoundError:
print("Python-magic is recommended for better detection of mimetypes")
_HAS_MAGIC = False
try:
import requests
_DO_HTTP = True
@ -1614,6 +1607,7 @@ class GeminiItem():
f.close()
def get_mime(self):
#Beware, this one is really a shaddy ad-hoc function
if self.mime:
return self.mime
elif self.is_cache_valid():
@ -1624,8 +1618,10 @@ class GeminiItem():
mime = "Local Folder"
elif path.endswith(".gmi"):
mime = "text/gemini"
elif _HAS_MAGIC :
mime = magic.from_file(path,mime=True)
elif shutil.which("file") :
#mime = magic.from_file(path,mime=True)
output = subprocess.run("file -b --mime-type %s"%path,shell=True,capture_output=True)
mime = output.stdout.decode().strip()
mime2,encoding = mimetypes.guess_type(path,strict=False)
#If we hesitate between html and xml, takes the xml one
#because the FeedRendered fallback to HtmlRenderer
@ -1637,8 +1633,9 @@ class GeminiItem():
else:
mime,encoding = mimetypes.guess_type(path,strict=False)
#gmi Mimetype is not recognized yet
if not mime and not _HAS_MAGIC :
print("Cannot guess the mime type of the file. Install Python-magic")
if not mime and not shutil.which("file") :
print("Cannot guess the mime type of the file. Please install \"file\".")
print("(and send me an email, Im curious of systems without \"file\" installed!")
if mime.startswith("text") and mime not in _FORMAT_RENDERERS:
if mime2 and mime2 in _FORMAT_RENDERERS:
mime = mime2
@ -3120,7 +3117,6 @@ Marks are temporary until shutdown (not saved to disk)."""
output += "===========\n"
output += "Highly recommended:\n"
output += " - python-cryptography : " + has(_HAS_CRYPTOGRAPHY)
output += " - python-magic : " + has(_HAS_MAGIC)
output += " - xdg-open : " + has(_HAS_XDGOPEN)
output += "\nWeb browsing:\n"
output += " - python-requests : " + has(_DO_HTTP)

View File

@ -1 +1 @@
sudo apt install xdg-utils xsel ripgrep chafa timg python3-cryptography python3-magic python3-requests python3-feedparser python3-bs4 python3-readability python3-pil python3-setproctitle
sudo apt install file xdg-utils xsel ripgrep chafa timg python3-cryptography python3-requests python3-feedparser python3-bs4 python3-readability python3-pil python3-setproctitle