forked from solderpunk/AV-98
Compare commits
39 Commits
Author | SHA1 | Date |
---|---|---|
Lionel Dricot | 3155585c9e | |
Lionel Dricot | 2e02d06b0e | |
Lionel Dricot | ed019fa04e | |
Lionel Dricot | 91e8b7aa16 | |
Lionel Dricot | b3051efe72 | |
Lionel Dricot | 9609a8d91f | |
Lionel Dricot | 2034821325 | |
Lionel Dricot | a6fee03d2b | |
Lionel Dricot | 7ba6bac5a4 | |
Lionel Dricot | 26ed1769de | |
Lionel Dricot | 9ee95e7a1b | |
Lionel Dricot | 7786b91993 | |
Lionel Dricot | 3051f60253 | |
Lionel Dricot | dade6a3bda | |
Lionel Dricot | eed83a7a95 | |
Lionel Dricot | 767ab82f29 | |
Lionel Dricot | 72ea43a59c | |
Lionel Dricot | d95d4dc5af | |
Lionel Dricot | 1a3d839ab3 | |
Lionel Dricot | 268e50a781 | |
Lionel Dricot | cd3177ac87 | |
Lionel Dricot | ce65850987 | |
Lionel Dricot | c7734e3a92 | |
Lionel Dricot | 0b0fcc3e42 | |
Lionel Dricot | 0cd988b055 | |
Lionel Dricot | 965f8916c2 | |
Lionel Dricot | 4fd8b89f49 | |
Lionel Dricot | b745b04f7a | |
Lionel Dricot | a7c8ed33d5 | |
Lionel Dricot | 6d43b13520 | |
Lionel Dricot | 0a385d5334 | |
Lionel Dricot | ef808afe1d | |
Lionel Dricot | 3c760c914a | |
Lionel Dricot | 76b00b8c04 | |
Lionel Dricot | a6974bb404 | |
Lionel Dricot | 644e8ba08e | |
Lionel Dricot | 927017d143 | |
Lionel Dricot | ea36f45d94 | |
Lionel Dricot | 86a67d47fa |
|
@ -1,5 +1,11 @@
|
||||||
# Offpunk History
|
# Offpunk History
|
||||||
|
|
||||||
|
## 2.0 - unreleased
|
||||||
|
This is an an experimental and unstable release. Lot of breakages are expected.
|
||||||
|
Wait for 2.1 if you are not willing to do testing/bug reporting.
|
||||||
|
- New command-line tool: "netcache"
|
||||||
|
- New command-line tool: "ansirenderer"
|
||||||
|
|
||||||
## 1.10 - unreleased
|
## 1.10 - unreleased
|
||||||
- IMPORTANT : new optional dependency : python-chardet
|
- IMPORTANT : new optional dependency : python-chardet
|
||||||
- IMPORTANT : Gopher directory index filename changed from "index.txt" to "gophermap". To update the cache to the new format run the `migrate-offpunk-cache` script (Sotiris Papatheodorou)
|
- IMPORTANT : Gopher directory index filename changed from "index.txt" to "gophermap". To update the cache to the new format run the `migrate-offpunk-cache` script (Sotiris Papatheodorou)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
3080
offpunk.py
3080
offpunk.py
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,57 @@
|
||||||
|
#!/bin/python
|
||||||
|
|
||||||
|
#This file contains some utilities common to offpunk, ansirenderer and netcache.
|
||||||
|
#Currently, there are the following utilities:
|
||||||
|
#
|
||||||
|
# run : run a shell command and get the results with some security
|
||||||
|
# term_width : get or set the width to display on the terminal
|
||||||
|
|
||||||
|
import os
|
||||||
|
import io
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
import shlex
|
||||||
|
|
||||||
|
# In terms of arguments, this can take an input file/string to be passed to
|
||||||
|
# stdin, a parameter to do (well-escaped) "%" replacement on the command, a
|
||||||
|
# flag requesting that the output go directly to the stdout, and a list of
|
||||||
|
# additional environment variables to set.
|
||||||
|
def run(cmd, *, input=None, parameter=None, direct_output=False, env={}):
|
||||||
|
#print("running %s"%cmd)
|
||||||
|
if parameter:
|
||||||
|
cmd = cmd % shlex.quote(parameter)
|
||||||
|
#following requires python 3.9 (but is more elegant/explicit):
|
||||||
|
# env = dict(os.environ) | env
|
||||||
|
e = os.environ
|
||||||
|
e.update(env)
|
||||||
|
if isinstance(input, io.IOBase):
|
||||||
|
stdin = input
|
||||||
|
input = None
|
||||||
|
else:
|
||||||
|
if input:
|
||||||
|
input = input.encode()
|
||||||
|
stdin = None
|
||||||
|
if not direct_output:
|
||||||
|
# subprocess.check_output() wouldn't allow us to pass stdin.
|
||||||
|
result = subprocess.run(cmd, check=True, env=e, input=input,
|
||||||
|
shell=True, stdin=stdin, stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT)
|
||||||
|
return result.stdout.decode()
|
||||||
|
else:
|
||||||
|
subprocess.run(cmd, env=e, input=input, shell=True, stdin=stdin)
|
||||||
|
|
||||||
|
|
||||||
|
global TERM_WIDTH
|
||||||
|
TERM_WIDTH = 80
|
||||||
|
|
||||||
|
def term_width(new_width=None):
|
||||||
|
if new_width:
|
||||||
|
global TERM_WIDTH
|
||||||
|
TERM_WIDTH = new_width
|
||||||
|
width = TERM_WIDTH
|
||||||
|
cur = shutil.get_terminal_size()[0]
|
||||||
|
if cur < width:
|
||||||
|
width = cur
|
||||||
|
return width
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/python
|
||||||
|
#opnk stand for "Open like a PuNK".
|
||||||
|
#It will open any file or URL and display it nicely in less.
|
||||||
|
#If not possible, it will fallback to xdg-open
|
||||||
|
#URL are retrieved through netcache
|
||||||
|
import netcache
|
||||||
|
import offutils
|
||||||
|
|
||||||
|
class opencache():
|
||||||
|
def __init__(self):
|
||||||
|
self.temp_files = {}
|
||||||
|
self.rendererdic = {}
|
||||||
|
|
||||||
|
def opnk(inpath,terminal=True):
|
||||||
|
#if terminal = False, we don’t try to open in the terminal,
|
||||||
|
#we immediately fallback to xdg-open.
|
||||||
|
#netcache currently provide the path if it’s a file.
|
||||||
|
#may this should be migrated here.
|
||||||
|
path = netcache.get_cache_path(inpath)
|
||||||
|
|
||||||
|
#TODO: migrate here ansirenderer display
|
||||||
|
1. À partir du path, tenter le ansirenderer
|
||||||
|
2. Sauver le rendu dans self.temp_files[mode] (donc le mode doit être passé à opnk)
|
||||||
|
3. Sauver le renderer dans self.rendererdic
|
||||||
|
3. Donner à less
|
||||||
|
4. sinon, donner à xdg-open
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("content",metavar="INPUT", nargs="*", type=argparse.FileType("r"),
|
||||||
|
default=sys.stdin, help="Path to the file or URL to open")
|
||||||
|
args = parser.parse_args()
|
||||||
|
cache = opencache()
|
||||||
|
for f in args.content:
|
||||||
|
cache.opnk(f)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue