forked from axiom-team/jaklis
Skip dunikey if don't needed
This commit is contained in:
parent
fd0f4dbe16
commit
0841ffcf49
49
jaklis.py
49
jaklis.py
|
@ -105,30 +105,47 @@ def createTmpDunikey():
|
|||
|
||||
return keyPath
|
||||
|
||||
# if not cmd in ('history','balance','get') and args.profile:
|
||||
# print('pubpass')
|
||||
# Check if we need dunikey
|
||||
try:
|
||||
pubkey = args.pubkey
|
||||
except:
|
||||
pubkey = False
|
||||
try:
|
||||
profile = args.profile
|
||||
except:
|
||||
profile = False
|
||||
|
||||
if args.key:
|
||||
dunikey = args.key
|
||||
if cmd in ('history','balance','get') and (pubkey or profile):
|
||||
noNeedDunikey = True
|
||||
keyPath = False
|
||||
try:
|
||||
dunikey = args.pubkey
|
||||
except:
|
||||
dunikey = args.profile
|
||||
else:
|
||||
dunikey = os.getenv('DUNIKEY')
|
||||
if not dunikey:
|
||||
keyPath = createTmpDunikey()
|
||||
dunikey = keyPath
|
||||
else:
|
||||
noNeedDunikey = False
|
||||
if args.key:
|
||||
dunikey = args.key
|
||||
keyPath = False
|
||||
if not os.path.isfile(dunikey):
|
||||
HOME = os.getenv("HOME")
|
||||
dunikey = HOME + dunikey
|
||||
else:
|
||||
dunikey = os.getenv('DUNIKEY')
|
||||
if not dunikey:
|
||||
keyPath = createTmpDunikey()
|
||||
dunikey = keyPath
|
||||
else:
|
||||
keyPath = False
|
||||
if not os.path.isfile(dunikey):
|
||||
sys.stderr.write('Le fichier de trousseau {0} est introuvable.\n'.format(dunikey))
|
||||
sys.exit(1)
|
||||
HOME = os.getenv("HOME")
|
||||
dunikey = HOME + dunikey
|
||||
if not os.path.isfile(dunikey):
|
||||
sys.stderr.write('Le fichier de trousseau {0} est introuvable.\n'.format(dunikey))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Construct CesiumPlus object
|
||||
if cmd in ("read","send","delete","set","get","erase","like","unlike"):
|
||||
from lib.cesium import CesiumPlus
|
||||
|
||||
if args.node:
|
||||
pod = args.node
|
||||
else:
|
||||
|
@ -136,7 +153,7 @@ if cmd in ("read","send","delete","set","get","erase","like","unlike"):
|
|||
if not pod:
|
||||
pod="https://g1.data.le-sou.org"
|
||||
|
||||
cesium = CesiumPlus(dunikey, pod)
|
||||
cesium = CesiumPlus(dunikey, pod, noNeedDunikey)
|
||||
|
||||
# Messaging
|
||||
if cmd == "read":
|
||||
|
@ -195,7 +212,7 @@ elif cmd in ("pay","history","balance"):
|
|||
else:
|
||||
destPubkey = False
|
||||
|
||||
gva = GvaApi(dunikey, node, destPubkey)
|
||||
gva = GvaApi(dunikey, node, destPubkey, noNeedDunikey)
|
||||
|
||||
if cmd == "pay":
|
||||
gva.pay(args.amount, args.comment, args.mempool, args.verbose)
|
||||
|
|
|
@ -48,7 +48,7 @@ class CesiumPlus(CesiumCommon):
|
|||
return result
|
||||
|
||||
def get(self, profile=None, avatar=None):
|
||||
getProfile = Profiles(self.dunikey, self.pod)
|
||||
getProfile = Profiles(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
if not profile:
|
||||
profile = self.pubkey
|
||||
if not re.match(PUBKEY_REGEX, profile) or len(profile) > 45:
|
||||
|
@ -72,7 +72,7 @@ class CesiumPlus(CesiumCommon):
|
|||
#################### Likes ####################
|
||||
|
||||
def readLikes(self, profile=False):
|
||||
likes = ReadLikes(self.dunikey, self.pod)
|
||||
likes = ReadLikes(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
document = likes.configDoc(profile)
|
||||
result = likes.sendDocument(document)
|
||||
result = likes.parseResult(result)
|
||||
|
|
|
@ -13,7 +13,9 @@ def pp_json(json_thing, sort=True, indents=4):
|
|||
return None
|
||||
|
||||
class CesiumCommon:
|
||||
def __init__(self, dunikey, pod):
|
||||
def __init__(self, dunikey, pod, noNeedDunikey=False):
|
||||
self.pod = pod
|
||||
self.noNeedDunikey = noNeedDunikey
|
||||
# Get my pubkey from my private key
|
||||
try:
|
||||
self.dunikey = dunikey
|
||||
|
@ -23,8 +25,10 @@ class CesiumCommon:
|
|||
sys.stderr.write("Please fill the path to your private key (PubSec)\n")
|
||||
sys.exit(1)
|
||||
|
||||
self.pubkey = get_privkey(dunikey, "pubsec").pubkey
|
||||
self.pod = pod
|
||||
if noNeedDunikey:
|
||||
self.pubkey = self.dunikey
|
||||
else:
|
||||
self.pubkey = get_privkey(dunikey, "pubsec").pubkey
|
||||
|
||||
if not re.match(PUBKEY_REGEX, self.pubkey) or len(self.pubkey) > 45:
|
||||
sys.stderr.write("La clé publique n'est pas au bon format.\n")
|
||||
|
|
|
@ -5,10 +5,15 @@ from lib.gvaHistory import History
|
|||
from lib.gvaBalance import Balance
|
||||
|
||||
class GvaApi():
|
||||
def __init__(self, dunikey, node, pubkey):
|
||||
def __init__(self, dunikey, node, pubkey, noNeedDunikey=False):
|
||||
self.noNeedDunikey = noNeedDunikey
|
||||
self.dunikey = dunikey
|
||||
self.node = node
|
||||
self.pubkey = get_privkey(dunikey, "pubsec").pubkey
|
||||
if noNeedDunikey:
|
||||
self.pubkey = self.dunikey
|
||||
else:
|
||||
self.pubkey = get_privkey(dunikey, "pubsec").pubkey
|
||||
|
||||
if pubkey:
|
||||
self.destPubkey = pubkey
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue