1
1
mirror of https://github.com/r4sas/PBinCLI synced 2025-01-25 14:04:33 +00:00
PBinCLI/pbincli/utils.py

27 lines
666 B
Python
Raw Normal View History

import json, ntpath, os
from base64 import b64encode, b64decode
2017-02-18 21:00:40 +03:00
class PBinCLIException(Exception):
pass
def path_leaf(path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
2017-02-18 21:00:40 +03:00
def check_readable(f):
2018-02-12 17:28:18 +03:00
# Checks if path exists and readable
2017-02-18 21:00:40 +03:00
if not os.path.exists(f) or not os.access(f, os.R_OK):
raise PBinCLIException("Error accessing path: {}".format(f))
2017-02-18 21:00:40 +03:00
def check_writable(f):
2018-02-12 17:28:18 +03:00
# Checks if path is writable
2017-02-18 21:00:40 +03:00
if not os.access(os.path.dirname(f) or ".", os.W_OK):
raise PBinCLIException("Path is not writable: {}".format(f))
2017-02-20 15:13:42 +03:00
2019-06-02 14:04:38 +00:00
def json_encode(s):
return json.dumps(s, separators=(',',':')).encode()