Skip to content

Commit

Permalink
Improved Display, Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Sep 1, 2017
1 parent 80c0990 commit 070d5ae
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
5 changes: 0 additions & 5 deletions config.ini

This file was deleted.

62 changes: 62 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import configobj
import os


def write_config():
# Creating a config file
try:
os.chdir(os.path.expanduser(os.path.join('~', '')))
os.makedirs('.config' + os.sep + "ptcl")
os.chdir('.config' + os.sep + "ptcl")

except OSError:
# If already exists
pass

config = configobj.ConfigObj()
DEFAULT = {'mask': '192.168.1.1', 'username': 'admin', 'password': 'admin'}
mask = raw_input("Leave empty for default configuration.\nPlease enter router gateway\t(Default 192.168.1.1)\t: ")

if mask:
DEFAULT['mask'] = mask
username = raw_input("Please enter router username\t(Default admin)\t: ")

if username:
DEFAULT['username'] = username
password = raw_input("Please enter router password\t(Default admin)\t: ")

if password:
DEFAULT['password'] = password
config['Router-Auth'] = DEFAULT
config['Aliases'] = {}

with open('config.ini', 'w') as configfile:
config.write(configfile)
print '\nConfiguration file Generated.'


def set_alias():
# Defining custom aliases
config = configobj.ConfigObj('config.ini')

while True:
hostname = raw_input("Set Alias for hosname: ")
if hostname == 'q':
break
macaddress= raw_input("Enter it\'s macaddress: ")

if macaddress == 'q':
break

else:
if hostname not in config["Aliases"]:
config["Aliases"][hostname] = macaddress
with open('config.ini', 'r+') as configfile:
config.write(configfile)
else:
print "Already Present."

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

0 comments on commit 070d5ae

Please sign in to comment.