mirror of
https://github.com/r4sas/PBinCLI
synced 2025-02-09 13:24:34 +00:00
commit
12c9c8db3b
27
cli
27
cli
@ -5,6 +5,18 @@ import pbincli.actions
|
|||||||
from pbincli.api import PrivateBin
|
from pbincli.api import PrivateBin
|
||||||
from pbincli.utils import PBinCLIException
|
from pbincli.utils import PBinCLIException
|
||||||
|
|
||||||
|
CONFIG_PATHS = [os.path.join(".", "pbincli.conf", ),
|
||||||
|
os.path.join(os.getenv("HOME") or "~", ".config", "pbincli", "pbincli.conf") ]
|
||||||
|
|
||||||
|
def read_config(filename):
|
||||||
|
"""Read config variables from a file"""
|
||||||
|
settings = {}
|
||||||
|
with open(filename) as f:
|
||||||
|
for l in f.readlines():
|
||||||
|
key, value = l.strip().split("=")
|
||||||
|
settings[key.strip()] = value.strip()
|
||||||
|
|
||||||
|
return settings
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
@ -49,10 +61,19 @@ def main():
|
|||||||
# parse arguments
|
# parse arguments
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
server = os.getenv("PRIVATEBIN_SERVER", "https://paste.i2pd.xyz/")
|
CONFIG = {"server": "https://paste.i2pd.xyz/",
|
||||||
proxy = os.getenv("PRIVATEBIN_PROXY")
|
"proxy": None}
|
||||||
|
|
||||||
api_client = PrivateBin(server, proxy=proxy)
|
for p in CONFIG_PATHS:
|
||||||
|
is os.path.exists(p):
|
||||||
|
CONFIG.update(read_config(p))
|
||||||
|
break
|
||||||
|
|
||||||
|
for key in CONFIG.keys():
|
||||||
|
var = "PRIVATEBIN_{}".format(key.upper())
|
||||||
|
if var in os.environ: CONFIG[key] = os.getenv(var)
|
||||||
|
|
||||||
|
api_client = PrivateBin(CONFIG["server"], proxy=CONFIG["proxy"])
|
||||||
|
|
||||||
if hasattr(args, "func"):
|
if hasattr(args, "func"):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user