Skip to content

Commit

Permalink
Fixed config
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Sep 1, 2017
1 parent cf4c7af commit 2ce04db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
15 changes: 15 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import configobj
import os

config = ""

def write_config():
# Creating a config file
Expand Down Expand Up @@ -56,7 +57,21 @@ def set_alias():
else:
print "Already Present."


def get_alias():
# Return Aliases
config = configobj.ConfigObj('config.ini')
return config["Aliases"]


def config_check():
path = os.path.expanduser(os.path.join('~', '.config' + os.sep + 'ptcl'))

if os.path.exists(path):
os.chdir(path)
global config
config = configobj.ConfigObj('config.ini')
return True
else:
write_config()
return False
25 changes: 9 additions & 16 deletions ptcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
import os
from tabulate import tabulate

path = os.path.expanduser(os.path.join('~', '.config' + os.sep + 'ptcl'))

if os.path.exists(path):
os.chdir(path)
config = configobj.ConfigObj('config.ini')
ptcl = Router(mask=config["Router-Auth"]["mask"], password=config["Router-Auth"]["password"])

else:
print "Configuration file doesn't exists. Run it with --configure parameter.\nExecuting Fallback mode."
ptcl = Router(mask="192.168.10.1", password="123motorcross")
# ptcl = Router(password='ptcl')


def show_dhcpinfo():
'''
Expand Down Expand Up @@ -78,7 +66,15 @@ def main():
parser.add_argument('-sa', '--set-alias', help='Set custom alias for a device hostname.', action='store_true')
parser.add_argument('-c', '--cli', help='Silent mode.', nargs='?', default='False')
args = parser.parse_args()
# print args

if configure.config_check() == True:
if configure.config:
global ptcl
ptcl = Router(mask=configure.config["Router-Auth"]["mask"], password=configure.config["Router-Auth"]["password"])

else:
configure.config_check()
sys.exit("Please Re-run.")

if args.cli == 'False':
my_macs = configure.get_alias()
Expand Down Expand Up @@ -118,9 +114,6 @@ def main():
elif args.blocked_dev:
show_blocked_dev()

elif args.configure:
configure.write_config()

elif args.set_alias:
show_active_dev()
configure.set_alias()
Expand Down

0 comments on commit 2ce04db

Please sign in to comment.