[wip] url shortener support (#19)

Signed-off-by: r4sas <r4sas@i2pmail.org>
This commit is contained in:
r4sas
2019-09-17 08:55:59 +00:00
parent 6b6c33e545
commit 635c87dabd
6 changed files with 75 additions and 34 deletions

View File

@@ -1,9 +1,14 @@
import json, ntpath, os
import json, ntpath, os, sys
class PBinCLIException(Exception):
pass
def PBinCLIError(message):
print("PBinCLI Error: {}".format(message), file=sys.stderr)
exit(1)
def path_leaf(path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
@@ -12,13 +17,13 @@ def path_leaf(path):
def check_readable(f):
# Checks if path exists and readable
if not os.path.exists(f) or not os.access(f, os.R_OK):
raise PBinCLIException("Error accessing path: {}".format(f))
PBinCLIError("Error accessing path: {}".format(f))
def check_writable(f):
# Checks if path is writable
if not os.access(os.path.dirname(f) or ".", os.W_OK):
raise PBinCLIException("Path is not writable: {}".format(f))
PBinCLIError("Path is not writable: {}".format(f))
def json_encode(s):