vastly improved version command to see status of different features
This commit is contained in:
parent
5cf26e28fa
commit
fdd1f36de6
64
offpunk.py
64
offpunk.py
|
@ -58,9 +58,12 @@ except ModuleNotFoundError:
|
||||||
import textwrap
|
import textwrap
|
||||||
_HAS_ANSIWRAP = False
|
_HAS_ANSIWRAP = False
|
||||||
|
|
||||||
|
_HAS_CHAFA = shutil.which('chafa')
|
||||||
|
_HAS_XSEL = shutil.which('xsel')
|
||||||
try:
|
try:
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
if _HAS_ANSIWRAP and shutil.which('chafa'):
|
_HAS_PIL = True
|
||||||
|
if _HAS_ANSIWRAP and _HAS_CHAFA:
|
||||||
_RENDER_IMAGE = True
|
_RENDER_IMAGE = True
|
||||||
else:
|
else:
|
||||||
print("chafa and ansiwrap are required to render images in terminal")
|
print("chafa and ansiwrap are required to render images in terminal")
|
||||||
|
@ -68,6 +71,7 @@ try:
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
print("python-pil, chafa and ansiwrap are required to render images")
|
print("python-pil, chafa and ansiwrap are required to render images")
|
||||||
_RENDER_IMAGE = False
|
_RENDER_IMAGE = False
|
||||||
|
_HAS_PIL = False
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -93,10 +97,17 @@ except ModuleNotFoundError:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from readability import Document
|
from readability import Document
|
||||||
from bs4 import BeautifulSoup
|
_HAS_READABILITY = True
|
||||||
_DO_HTML = True
|
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
_DO_HTML = False
|
_HAS_READABILITY = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
_HAS_SOUP = True
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
_HAS_SOUP = False
|
||||||
|
|
||||||
|
_DO_HTML = _HAS_SOUP and _HAS_READABILITY
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import feedparser
|
import feedparser
|
||||||
|
@ -108,10 +119,12 @@ except ModuleNotFoundError:
|
||||||
# There are two conflicting xdg modules, we try to work with both
|
# There are two conflicting xdg modules, we try to work with both
|
||||||
try:
|
try:
|
||||||
from xdg import BaseDirectory
|
from xdg import BaseDirectory
|
||||||
|
_HAS_XDG = True
|
||||||
_CACHE_PATH = BaseDirectory.save_cache_path("offpunk/")
|
_CACHE_PATH = BaseDirectory.save_cache_path("offpunk/")
|
||||||
_CONFIG_DIR = BaseDirectory.save_config_path("offpunk/")
|
_CONFIG_DIR = BaseDirectory.save_config_path("offpunk/")
|
||||||
_DATA_DIR = BaseDirectory.save_data_path("offpunk/")
|
_DATA_DIR = BaseDirectory.save_data_path("offpunk/")
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
|
_HAS_XDG = False
|
||||||
_CACHE_PATH = os.path.expanduser("~/.cache/offpunk/")
|
_CACHE_PATH = os.path.expanduser("~/.cache/offpunk/")
|
||||||
_CONFIG_DIR = None
|
_CONFIG_DIR = None
|
||||||
## Look for pre-existing config directory, if any
|
## Look for pre-existing config directory, if any
|
||||||
|
@ -161,6 +174,7 @@ _ABBREVS = {
|
||||||
"h": "history",
|
"h": "history",
|
||||||
"hist": "history",
|
"hist": "history",
|
||||||
"l": "less",
|
"l": "less",
|
||||||
|
"mv": "move",
|
||||||
"n": "next",
|
"n": "next",
|
||||||
"off": "offline",
|
"off": "offline",
|
||||||
"on": "online",
|
"on": "online",
|
||||||
|
@ -368,7 +382,6 @@ class GopherRenderer(AbstractRenderer):
|
||||||
|
|
||||||
#menu_or_text
|
#menu_or_text
|
||||||
def render(self,body,width=None,mode=None):
|
def render(self,body,width=None,mode=None):
|
||||||
print("Gopher rendering with width %s" %width)
|
|
||||||
if not width:
|
if not width:
|
||||||
width = TERM_WIDTH
|
width = TERM_WIDTH
|
||||||
try:
|
try:
|
||||||
|
@ -433,6 +446,7 @@ class FolderRenderer(GemtextRenderer):
|
||||||
if self.url != listdir:
|
if self.url != listdir:
|
||||||
return "This is folder %s" %self.url
|
return "This is folder %s" %self.url
|
||||||
else:
|
else:
|
||||||
|
self.title = "My lists"
|
||||||
lists = []
|
lists = []
|
||||||
if os.path.exists(listdir):
|
if os.path.exists(listdir):
|
||||||
listfiles = os.listdir(listdir)
|
listfiles = os.listdir(listdir)
|
||||||
|
@ -1426,7 +1440,6 @@ class GeminiClient(cmd.Cmd):
|
||||||
print(err)
|
print(err)
|
||||||
else:
|
else:
|
||||||
if print_error:
|
if print_error:
|
||||||
crash
|
|
||||||
print("ERROR4: " + str(type(err)) + " : " + str(err))
|
print("ERROR4: " + str(type(err)) + " : " + str(err))
|
||||||
print("\n" + str(err.with_traceback(None)))
|
print("\n" + str(err.with_traceback(None)))
|
||||||
return
|
return
|
||||||
|
@ -2301,7 +2314,7 @@ class GeminiClient(cmd.Cmd):
|
||||||
Use with "url" as argument to only copy the adress.
|
Use with "url" as argument to only copy the adress.
|
||||||
Use with "raw" to copy the content as seen in your terminal (not gemtext)"""
|
Use with "raw" to copy the content as seen in your terminal (not gemtext)"""
|
||||||
if self.gi:
|
if self.gi:
|
||||||
if shutil.which('xsel'):
|
if _HAS_XSEL:
|
||||||
if args and args[0] == "url":
|
if args and args[0] == "url":
|
||||||
subprocess.call(("echo %s |xsel -b -i" % self.gi.url), shell=True)
|
subprocess.call(("echo %s |xsel -b -i" % self.gi.url), shell=True)
|
||||||
elif args and args[0] == "raw":
|
elif args and args[0] == "raw":
|
||||||
|
@ -2473,8 +2486,39 @@ Think of it like marks in vi: 'mark a'='ma' and 'go a'=''a'."""
|
||||||
print("Invalid mark, must be one letter")
|
print("Invalid mark, must be one letter")
|
||||||
|
|
||||||
def do_version(self, line):
|
def do_version(self, line):
|
||||||
"""Display version information."""
|
"""Display version and system information."""
|
||||||
print("Offpunk " + _VERSION)
|
def has(value):
|
||||||
|
if value:
|
||||||
|
return "\t\x1b[1;32mInstalled\x1b[0m\n"
|
||||||
|
else:
|
||||||
|
return "\t\x1b[1;31mNot Installed\x1b[0m\n"
|
||||||
|
output = "Offpunk " + _VERSION + "\n"
|
||||||
|
output += "===========\n"
|
||||||
|
output += " - python-editor : " + has(_HAS_EDITOR)
|
||||||
|
output += " - python-ansiwrap : " + has(_HAS_ANSIWRAP)
|
||||||
|
output += " - python-pil : " + has(_HAS_PIL)
|
||||||
|
output += " - python-cryptography : " + has(_HAS_CRYPTOGRAPHY)
|
||||||
|
output += " - python-magic : " + has(_HAS_MAGIC)
|
||||||
|
output += " - python-requests : " + has(_DO_HTTP)
|
||||||
|
output += " - python-feedparser : " + has(_DO_FEED)
|
||||||
|
output += " - python-bs4 : " + has(_HAS_SOUP)
|
||||||
|
output += " - python-readability : " + has(_HAS_READABILITY)
|
||||||
|
output += " - python-xdg : " + has(_HAS_XDG)
|
||||||
|
output += " - chafa : " + has(_HAS_CHAFA)
|
||||||
|
output += " - xsel : " + has(_HAS_XSEL)
|
||||||
|
|
||||||
|
output += "\nFeatures :\n"
|
||||||
|
output += " - Render images (ansiwrap,pil,chafa) : " + has(_RENDER_IMAGE)
|
||||||
|
output += " - Render HTML (bs4, readability) : " + has(_DO_HTML)
|
||||||
|
output += " - Render Atom/RSS feeds (feedparser) : " + has(_DO_FEED)
|
||||||
|
output += " - Connect to http/https (requests) : " + has(_DO_HTTP)
|
||||||
|
output += " - copy to/from clipboard (xsel) : " + has(_HAS_XSEL)
|
||||||
|
output += "\n"
|
||||||
|
output += "Config directory : " + _CONFIG_DIR + "\n"
|
||||||
|
output += "User Data directory : " + _DATA_DIR + "\n"
|
||||||
|
output += "CACHE : " + _CACHE_PATH
|
||||||
|
|
||||||
|
print(output)
|
||||||
|
|
||||||
### Stuff that modifies the lookup table
|
### Stuff that modifies the lookup table
|
||||||
def do_ls(self, line):
|
def do_ls(self, line):
|
||||||
|
@ -2887,7 +2931,7 @@ If current page was not in a list, this command is similar to `add LIST`."""
|
||||||
- list edit $LIST : edit the list
|
- list edit $LIST : edit the list
|
||||||
- list delete $LIST : delete a list permanently (a confirmation is required)
|
- list delete $LIST : delete a list permanently (a confirmation is required)
|
||||||
See also :
|
See also :
|
||||||
- add $LIST (to add current page to list)
|
- add $LIST (to add current page to $LIST or, by default, to bookmarks)
|
||||||
- move $LIST (to add current page to list while removing from all others)
|
- move $LIST (to add current page to list while removing from all others)
|
||||||
- archive (to remove current page from all lists while adding to archives)"""
|
- archive (to remove current page from all lists while adding to archives)"""
|
||||||
listdir = os.path.join(_DATA_DIR,"lists")
|
listdir = os.path.join(_DATA_DIR,"lists")
|
||||||
|
|
Loading…
Reference in New Issue