Added default profile feature
This commit is contained in:
parent
76b3a3ee25
commit
1733e5779a
|
@ -51,7 +51,7 @@ optional arguments:
|
||||||
Private Keys is stored in ~/.twik.conf you need change it to match with chrome extension and android app:
|
Private Keys is stored in ~/.twik.conf you need change it to match with chrome extension and android app:
|
||||||
|
|
||||||
```
|
```
|
||||||
[Profile]
|
[Personal]
|
||||||
private_key = TFCY2AJI-NBPU-V01E-F7CP-PJIZNRKPF25W
|
private_key = TFCY2AJI-NBPU-V01E-F7CP-PJIZNRKPF25W
|
||||||
chars = 8
|
chars = 8
|
||||||
password_type = 1
|
password_type = 1
|
||||||
|
@ -59,6 +59,8 @@ github_chars = 12
|
||||||
github_password_type = 1
|
github_password_type = 1
|
||||||
|
|
||||||
[foobar]
|
[foobar]
|
||||||
|
# for set foobar as default profile
|
||||||
|
default = 1
|
||||||
private_key = VBHF4HAR-8M5Z-NK3B-KQWH-KG9ZYLER4916
|
private_key = VBHF4HAR-8M5Z-NK3B-KQWH-KG9ZYLER4916
|
||||||
chars = 22
|
chars = 22
|
||||||
password_type = 1
|
password_type = 1
|
||||||
|
|
|
@ -37,8 +37,8 @@ def main():
|
||||||
choices=range(4, 27),
|
choices=range(4, 27),
|
||||||
metavar="[4-26]",
|
metavar="[4-26]",
|
||||||
help="length of generated password [4-26]. Default: 12")
|
help="length of generated password [4-26]. Default: 12")
|
||||||
parser.add_argument("-p", "--profile", type=str, default='Profile',
|
parser.add_argument("-p", "--profile", type=str, default=None,
|
||||||
help="profile to use. Default:'Profile'")
|
help="profile to use. Default:'Personal'")
|
||||||
parser.add_argument("-t", "--passwordtype", type=int, choices=[1, 2, 3],
|
parser.add_argument("-t", "--passwordtype", type=int, choices=[1, 2, 3],
|
||||||
help='''
|
help='''
|
||||||
1 for ALPHANUMERIC_AND_SPECIAL_CHAR
|
1 for ALPHANUMERIC_AND_SPECIAL_CHAR
|
||||||
|
|
15
twik/util.py
15
twik/util.py
|
@ -76,10 +76,21 @@ class Util(object):
|
||||||
Get private key if not exists create new one
|
Get private key if not exists create new one
|
||||||
"""
|
"""
|
||||||
private_key = ''
|
private_key = ''
|
||||||
if self.config.has_option(self.profile, 'private_key'):
|
if self.profile == None and len(self.config.sections()) > 0:
|
||||||
|
for session in self.config.sections():
|
||||||
|
if self.config.has_option(session, 'default') and self.config.getboolean(session, 'default') == True:
|
||||||
|
self.profile = session
|
||||||
|
break
|
||||||
|
if self.profile == None:
|
||||||
|
self.profile = self.config.sections()[0]
|
||||||
|
print 'Using profile : %s' % self.profile
|
||||||
|
|
||||||
|
if self.profile and self.config.has_option(self.profile, 'private_key'):
|
||||||
private_key = self.config.get(self.profile, 'private_key')
|
private_key = self.config.get(self.profile, 'private_key')
|
||||||
else:
|
else:
|
||||||
private_key = privatekeygenerator()
|
private_key = privatekeygenerator()
|
||||||
|
if self.profile == None:
|
||||||
|
self.profile = 'Personal'
|
||||||
self.config.add_section(self.profile)
|
self.config.add_section(self.profile)
|
||||||
self.config.set(self.profile, 'private_key', private_key)
|
self.config.set(self.profile, 'private_key', private_key)
|
||||||
chars = self.chars
|
chars = self.chars
|
||||||
|
@ -90,6 +101,8 @@ class Util(object):
|
||||||
pass_type = 1
|
pass_type = 1
|
||||||
self.config.set(self.profile, 'chars', chars)
|
self.config.set(self.profile, 'chars', chars)
|
||||||
self.config.set(self.profile, 'password_type', pass_type)
|
self.config.set(self.profile, 'password_type', pass_type)
|
||||||
|
if self.profile == 'Personal':
|
||||||
|
self.config.set(self.profile, 'default', 1)
|
||||||
self.writeconfig()
|
self.writeconfig()
|
||||||
print 'New profile is generated'
|
print 'New profile is generated'
|
||||||
self.config.read(self.filename)
|
self.config.read(self.filename)
|
||||||
|
|
Loading…
Reference in New Issue