debug XDG folders

This commit is contained in:
Lionel Dricot 2023-07-31 17:56:08 +02:00
parent a6fee03d2b
commit 2034821325
3 changed files with 63 additions and 66 deletions

View File

@ -41,7 +41,7 @@ except ModuleNotFoundError:
less_version = 0 less_version = 0
if not shutil.which("less"): if not shutil.which("less"):
print("Please install the pager \"less\" to run Offpunk.") print("Please install the pager \"less\" to run Offpunk.")
print("If you wish to use another pager, send your request to offpunk@ploum.eu.") print("If you wish to use another pager, send me an email!")
print("(Im really curious to hear about people not having \"less\" on their system.)") print("(Im really curious to hear about people not having \"less\" on their system.)")
sys.exit() sys.exit()
output = run("less --version") output = run("less --version")
@ -1235,7 +1235,6 @@ def get_mime(path):
mime = "text/gemini" mime = "text/gemini"
return mime return mime
def renderer_from_file(path,url=None): def renderer_from_file(path,url=None):
mime = get_mime(path) mime = get_mime(path)
if not url: if not url:

View File

@ -11,6 +11,7 @@ import ssl
import glob import glob
import datetime import datetime
import hashlib import hashlib
import sqlite3
from ssl import CertificateError from ssl import CertificateError
try: try:
import chardet import chardet
@ -30,7 +31,7 @@ _home = os.path.expanduser('~')
cache_home = os.environ.get('XDG_CACHE_HOME') or\ cache_home = os.environ.get('XDG_CACHE_HOME') or\
os.path.join(_home,'.cache') os.path.join(_home,'.cache')
#_CACHE_PATH = os.path.join(cache_home,"offpunk/") #_CACHE_PATH = os.path.join(cache_home,"offpunk/")
#Debug: #Debug (TODO: get path from offpunk):
_CACHE_PATH = "/home/ploum/dev/netcache/" _CACHE_PATH = "/home/ploum/dev/netcache/"
_DATA_DIR = "/home/ploum/dev/netcache/" _DATA_DIR = "/home/ploum/dev/netcache/"
_CONFIG_DIR = "/home/ploum/dev/netcache/" _CONFIG_DIR = "/home/ploum/dev/netcache/"
@ -814,7 +815,7 @@ def _fetch_gemini(url,timeout=DEFAULT_TIMEOUT,**kwargs):
# TODO: another cert handling to refactor # TODO: another cert handling to refactor
# Remember that we showed the current cert to this domain... # Remember that we showed the current cert to this domain...
#TODO : accept badssl and automatic choice #TODO : accept badssl and automatic choice
validate_cert(address[4][0], host, cert,automatic_choice="y") _validate_cert(address[4][0], host, cert,automatic_choice="y")
# if self.client_certs["active"]: # if self.client_certs["active"]:
# self.active_cert_domains.append(host) # self.active_cert_domains.append(host)
# self.client_certs[host] = self.client_certs["active"] # self.client_certs[host] = self.client_certs["active"]

View File

@ -31,7 +31,6 @@ import random
import shlex import shlex
import shutil import shutil
import socket import socket
import sqlite3
import sys import sys
import time import time
import urllib.parse import urllib.parse
@ -82,6 +81,10 @@ _MAX_CACHE_AGE_SECS = 180
_GREP = "grep --color=auto" _GREP = "grep --color=auto"
#TODO: remove this debug code
_CACHE_PATH = "/home/ploum/dev/netcache/"
_DATA_DIR = "/home/ploum/dev/netcache/"
_CONFIG_DIR = "/home/ploum/dev/netcache/"
# Command abbreviations # Command abbreviations
_ABBREVS = { _ABBREVS = {
"..": "up", "..": "up",
@ -193,41 +196,41 @@ class GeminiItem():
# This method is used to load once the list of links in a gi # This method is used to load once the list of links in a gi
# Links can be followed, after a space, by a description/title # Links can be followed, after a space, by a description/title
#TODO: check all calls of get_links then move it to ansirenderer #TODO: remove this code
def get_links(self,mode=None): # def get_links(self,mode=None):
links = [] # links = []
toreturn = [] # toreturn = []
if self.renderer: # if self.renderer:
if not mode: # if not mode:
mode = self.renderer.last_mode # mode = self.renderer.last_mode
links = self.renderer.get_links(mode=mode) # links = self.renderer.get_links(mode=mode)
for l in links: # for l in links:
#split between link and potential name # #split between link and potential name
# check that l is non-empty # # check that l is non-empty
url = None # url = None
if l: # if l:
splitted = l.split(maxsplit=1) # splitted = l.split(maxsplit=1)
url = self.absolutise_url(splitted[0]) # url = self.absolutise_url(splitted[0])
if url and looks_like_url(url): # if url and looks_like_url(url):
if len(splitted) > 1: # if len(splitted) > 1:
#We add a name only for Gopher items # #We add a name only for Gopher items
if url.startswith("gopher://"): # if url.startswith("gopher://"):
newgi = GeminiItem(url,name=splitted[1]) # newgi = GeminiItem(url,name=splitted[1])
else: # else:
newgi = GeminiItem(url) # newgi = GeminiItem(url)
else: # else:
newgi = GeminiItem(url) # newgi = GeminiItem(url)
toreturn.append(newgi) # toreturn.append(newgi)
elif url and mode != "links_only" and url.startswith("data:image/"): # elif url and mode != "links_only" and url.startswith("data:image/"):
imgurl,imgdata = ansirenderer.looks_like_base64(url,self.url) # imgurl,imgdata = ansirenderer.looks_like_base64(url,self.url)
if imgurl: # if imgurl:
toreturn.append(GeminiItem(imgurl)) # toreturn.append(GeminiItem(imgurl))
else: # else:
toreturn.append(None) # toreturn.append(None)
else: # else:
# We must include a None item to keep the link count valid # # We must include a None item to keep the link count valid
toreturn.append(None) # toreturn.append(None)
return toreturn # return toreturn
#TODO: should be in ansirenderer #TODO: should be in ansirenderer
def get_subscribe_links(self): def get_subscribe_links(self):
@ -677,22 +680,16 @@ class GeminiClient(cmd.Cmd):
print("Please install xdg-open (usually from xdg-util package)") print("Please install xdg-open (usually from xdg-util package)")
return cmd_str return cmd_str
#TODO:remove format_geminiitem
def _format_geminiitem(self, index, gi, url=False):
if not gi:
line = "[%s] - No valid URL"%index
else:
protocol = "" if gi.scheme == "gemini" else " %s" % gi.scheme
line = "[%d%s] %s" % (index, protocol, gi.name or gi.url)
if gi.name and url:
line += " (%s)" % gi.url
return line
@needs_gi @needs_gi
def _show_lookup(self, offset=0, end=None, url=False): def _show_lookup(self, offset=0, end=None, show_url=False):
#TODO: change get_links to use the renderer for n, u in enumerate(self.get_renderer().get_links()[offset:end]):
for n, gi in enumerate(self.gi.get_links()[offset:end]): index = n+offset+1
print(self._format_geminiitem(n+offset+1, gi, url)) line = "[%s] %s" %(index,u)
#TODO: implement proper listing of url (with protocol and show_url)
# protocol = "" if gi.scheme == "gemini" else " %s" % gi.scheme
# line = "[%d%s] %s" % (index, protocol, gi.name or gi.url)
# line += " (%s)" % gi.url
print(line)
def _update_history(self, gi): def _update_history(self, gi):
# We never update while in sync_only # We never update while in sync_only
@ -1073,8 +1070,8 @@ Current tour can be listed with `tour ls` and scrubbed with `tour clear`."""
self.list_rm_url(l.url_mode(),"tour") self.list_rm_url(l.url_mode(),"tour")
elif line == "*": elif line == "*":
#TODO: change to use renderer.get_links and change list_add_line #TODO: change to use renderer.get_links and change list_add_line
for l in self.gi.get_links(): for l in self.get_renderer().get_links():
self.list_add_line("tour",gi=l,verbose=False) self.list_add_line("tour",gi=GeminiItem(l),verbose=False)
elif line == ".": elif line == ".":
self.list_add_line("tour",verbose=False) self.list_add_line("tour",verbose=False)
elif looks_like_url(line): elif looks_like_url(line):
@ -1084,12 +1081,11 @@ Current tour can be listed with `tour ls` and scrubbed with `tour clear`."""
if not list_path: if not list_path:
print("List %s does not exist. Cannot add it to tour"%(list)) print("List %s does not exist. Cannot add it to tour"%(list))
else: else:
gi = GeminiItem("list:///%s"%line) url = "list:///%s"%line
display = not self.sync_only display = not self.sync_only
if gi: #TODO : change get_links
#TODO : change get_links for l in self.get_renderer(url).get_links():
for l in gi.get_links(): self.list_add_line("tour",gi=GeminiItem(l),verbose=False)
self.list_add_line("tour",gi=l,verbose=False)
else: else:
for index in line.split(): for index in line.split():
try: try:
@ -1223,7 +1219,7 @@ Marks are temporary until shutdown (not saved to disk)."""
def do_ls(self, line): def do_ls(self, line):
"""List contents of current index. """List contents of current index.
Use 'ls -l' to see URLs.""" Use 'ls -l' to see URLs."""
self._show_lookup(url = "-l" in line) self._show_lookup(show_url = "-l" in line)
self.page_index = 0 self.page_index = 0
def do_search(self,line): def do_search(self,line):
@ -1635,7 +1631,8 @@ archives, which is a special historical list limited in size. It is similar to `
def list_get_links(self,list): def list_get_links(self,list):
list_path = self.list_path(list) list_path = self.list_path(list)
if list_path: if os.path.exists(list_path):
print("path is %s and exists %s"%(list_path,os.path.exists(list_path)))
return self.get_renderer("list:///%s"%list).get_links() return self.get_renderer("list:///%s"%list).get_links()
else: else:
return [] return []
@ -1652,8 +1649,8 @@ archives, which is a special historical list limited in size. It is similar to `
display = not self.sync_only display = not self.sync_only
if url: if url:
self._go_to_url(url,handle=display) self._go_to_url(url,handle=display)
#TODO url_mode ? #TODO : why returning the mode??
return gi.url_mode() return self.renderer(url).last_mode
def list_show(self,list): def list_show(self,list):
list_path = self.list_path(list) list_path = self.list_path(list)