Skip to content

Commit

Permalink
Modified scripts for resolving command line errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NovusEdge committed Apr 10, 2021
1 parent 0fbdbc9 commit 42543b5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
42 changes: 37 additions & 5 deletions docker_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import colorama
import argparse
import pathlib
import shlex
import sys
import os

PATH = pathlib.Path(__file__).parent.absolute()
os.chdir(PATH)

SUBPIPE = subprocess.PIPE


COLORS = {
"R": colorama.Fore.RED,
Expand All @@ -18,10 +21,30 @@


def make_image() -> None:
subprocess.run('docker', args=['build', '--no-cache', '-t', 'BTBMT', '.'], shell=True)
command = shlex.split('docker image inspect btbmt')
check_process = subprocess.Popen(command, stdout=SUBPIPE,
stderr=SUBPIPE, stdin=SUBPIPE)
out, err = check_process.communicate()
if out == b'[]\n':
command = shlex.split('docker build --no-cache -t btbmt .')

try:
make_process = subprocess.Popen(command, stdin=SUBPIPE)
make_process.communicate()

except KeyboardInterrupt:
make_process.kill()

def delete_image() -> None:
subprocess.run('docker', args=['rmi', '-f', 'BTBMT'], shell=True)
try:
command = shlex.split('docker rmi -f btbmt')
process = subprocess.Popen(command, stderr=SUBPIPE, stdin=SUBPIPE)
stderr = process.communicate()
if stderr[1] == b'Error: No such image: btbmt\n':
print(f"{COLORS['R']}[-] Error: No such image: btbmt{COLORS['RESET']}")

except KeyboardInterrupt:
process.kill()

def update_image() -> None:
delete_image()
Expand All @@ -31,14 +54,23 @@ def update_image() -> None:

def auto_run() -> None:
print(f"{COLORS['Y']}[*] Setting things up for docker...{COLORS['RESET']}")
command = shlex.split('docker image inspect btbmt')

try:
subprocess.run('docker', args=['image', 'inspect', 'BTBMT'], check=True)
update_image()
process = subprocess.Popen(command, stdout=SUBPIPE,
stderr=SUBPIPE, stdin=SUBPIPE)
process.communicate()

except KeyboardInterrupt:
process.kill()

except Exception as e:
except:
make_image()


finally:
update_image()

def main() -> None:
parser = argparse.ArgumentParser()

Expand Down
29 changes: 20 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pathlib
import logging
import shutil
import shlex
import sys
import os

Expand All @@ -22,28 +23,28 @@

def input_copy_file(dest: str, message: str):
try:
src = input(message)
src = input(message).strip()
shutil.copyfile(src, dest)
logging.info(f"{COLORS['G']}[+] Found the file {src}!{COLORS['RESET']}")
print(f"{COLORS['G']}\n[+] Found the file {src}!{COLORS['RESET']}")
except Exception as e:
logging.error(f"{COLORS['R']}[-] Couldn't find the file: {src}"
print(f"{COLORS['R']}\n[-] Couldn't find the file: {src} "
f"Please set it up.{COLORS['RESET']}")

def main():
if not os.isdir("binance-trade-bot"):
if not os.path.isdir("binance-trade-bot"):
os.system('git clone https://github.com/edeng23/binance-trade-bot')

isBTB = input(f"{COLORS['Y']}[*] Is there a BTB installation on your filesystem (y/n)?: ")
if isBTB in ['y', 'Y']:

input_copy_file("binance-trade-bot/user.cfg",
f"{COLORS['G']}[+] Enter path to user.cfg file: ")
f"{COLORS['G']}\n[+] Enter path to user.cfg file: {COLORS['RESET']}")

input_copy_file("binance-trade-bot/supported_coin_list",
f"{COLORS['G']}[+] Enter the path to supported_coin_list: ")
f"{COLORS['G']}\n[+] Enter the path to supported_coin_list: {COLORS['RESET']}")

input_copy_file("binance-trade-bot/config/apprise.yml",
f"{COLORS['G']}[+] Enter the path to apprise.yml file: ")
f"{COLORS['G']}\n[+] Enter the path to apprise.yml file: {COLORS['RESET']}")


elif isBTB in ['n', 'N']:
Expand All @@ -58,11 +59,21 @@ def main():
" running the bot in a docker container (y/n)?")

if docker in ['y', 'Y']:
subprocess.run('$(which python3) docker_setup.py')
command = shlex.split('python3 docker_setup.py')
try:
process = subprocess.Popen(command, stdin=subprocess.PIPE)
process.communicate()

except KeyboardInterrupt:
process.kill()

except Exception as e:
print(f"{COLORS['R']}[-] {e} {COLORS['RESET']}")

else:
print(f"[*] Skipping te setup for dockerizing the bot{COLORS['RESET']}")

return

print(f"{COLORS['G']}[*] All set!{COLORS['RESET']}")


Expand Down

0 comments on commit 42543b5

Please sign in to comment.