فهرست منبع

bin/deg: drop deg config, and use args instead

dasman 2 سال پیش
والد
کامیت
8c455abd0a
3فایلهای تغییر یافته به همراه17 افزوده شده و 99 حذف شده
  1. 17 21
      bin/deg/deg
  2. 0 11
      bin/deg/deg_config.toml
  3. 0 67
      bin/deg/src/util.py

+ 17 - 21
bin/deg/deg

@@ -23,7 +23,6 @@ import networkx as nx
 from datetime import datetime
 # import matplotlib.pyplot as plt
 import src.rpc
-import src.util
 
 from os.path import join
 
@@ -61,11 +60,6 @@ def graph(event, longest_path):
                 return "│ o"
         else:
             return "o  "
-            #  "│ o"
-            #  "o │"
-            #  "o━┪"
-            #  "o─┴"
-            #  "o━┯"
 
 # because tab character is broken in urwid texts
 def indent(num):
@@ -133,14 +127,14 @@ class DetailView(u.WidgetWrap):
 class App(object):
     
     def unhandled_input(self, key):
-        if key in ('q',):
+        if key in ('q', 'Q'):
             raise u.ExitMainLoop()
         # if key == 'r':
         #     await self.update_data(self.config)
         if key == 'enter':
             self.current_view = self.frame2
             self.loop.widget = self.frame2
-        if key == 'b':
+        if key in ('b', 'B'):
             self.current_view = self.frame1
             self.loop.widget = self.frame1
 
@@ -182,10 +176,6 @@ class App(object):
             self.config = config
             dag_dict = await recreate_dag(config, replay_mode)
             dag_list = list(dag_dict.items())
-            # sorted_dag = sorted(dag_list, key=lambda x:x[1]['layer'])
-
-            # genesis_hash = sorted_dag[0][0]
-
             parent_child_pairs = []
             for item in dag_list:
                 parents = item[1]['parents']
@@ -250,15 +240,21 @@ async def recreate_dag(config, replay_mode):
         
 
 async def main(argv):
-
-    os = src.util.get_os()
-    config_path = src.util.user_config_dir('darkfi', os)
-
-    suffix = '.toml'
-    filename = 'deg_config'
-    path = join(config_path, filename + suffix)
-    config = src.util.spawn_config(path)
-    config = config['nodes'][0]
+    val = str('127.0.0.1:26660')
+    for i in range(1, len(sys.argv)):
+        if sys.argv[i] == "-e":
+            try:
+                val = sys.argv[i+1]
+            except IndexError:
+                print("Please provide a value for \'-e\'")
+                exit(-1)
+            break
+    config = {}
+    try:
+        config['host'], config['port'] = val.split(':')
+    except ValueError:
+        print("Please provide a port as in: 127.0.0.1:26660")
+        exit(-1)
 
     replay_mode = False
     if len(argv) > 1:

+ 0 - 11
bin/deg/deg_config.toml

@@ -1,11 +0,0 @@
-[[nodes]]
-name = "darkirc"
-host = "localhost"
-port = 26660
-type = "NORMAL"
-
-[[nodes]]
-name = "genev"
-host = "localhost"
-port = 28880
-type = "NORMAL"

+ 0 - 67
bin/deg/src/util.py

@@ -1,67 +0,0 @@
-# This file is part of DarkFi (https://dark.fi)
-#
-# Copyright (C) 2020-2024 Dyne.org foundation
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-import os
-import sys
-import toml
-import platform
-
-def get_os():
-   if sys.platform.startswith('java'):
-      os_name = platform.java_ver()[3][0]
-      if os_name.startswith('Windows'): 
-          system = 'win32'
-      elif os_name.startswith('Mac'):
-          system = 'macOS'
-      else: 
-          system = 'linux'
-   else:
-        system = sys.platform
-   return system
-
-def user_config_dir(appname, system):
-   if system == "win32":
-       path = windows_dir(appname)
-   elif system == 'macOS':
-       path = os.path.expanduser('~/Library/Preferences/')
-       path = os.path.join(path, appname)
-   else:
-       path = os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config"))
-       path = os.path.join(path, appname)
-   return path
-
-def windows_dir(appname):
-   appauthor = appname
-   const = "CSIDL_APPDATA"
-   path = os.path.normpath(_get_win_folder(const))
-   path = os.path.join(path, appname)
-   return path
-
-def spawn_config(path):
-    file_exists = os.path.exists(path)
-    if file_exists:
-        with open(path) as f:
-            cfg = toml.load(f)
-            return cfg
-    else:
-        with open('deg_config.toml') as f:
-            cfg = toml.load(f)
-        with open(path, 'w') as f:
-            toml.dump(cfg, f)
-        print(f"Config file created in {path}. Please review it and try again.")
-        sys.exit(0)
-