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:
|
||||
|
||||
```
|
||||
[Profile]
|
||||
[Personal]
|
||||
private_key = TFCY2AJI-NBPU-V01E-F7CP-PJIZNRKPF25W
|
||||
chars = 8
|
||||
password_type = 1
|
||||
|
@ -59,6 +59,8 @@ github_chars = 12
|
|||
github_password_type = 1
|
||||
|
||||
[foobar]
|
||||
# for set foobar as default profile
|
||||
default = 1
|
||||
private_key = VBHF4HAR-8M5Z-NK3B-KQWH-KG9ZYLER4916
|
||||
chars = 22
|
||||
password_type = 1
|
||||
|
|
|
@ -37,8 +37,8 @@ def main():
|
|||
choices=range(4, 27),
|
||||
metavar="[4-26]",
|
||||
help="length of generated password [4-26]. Default: 12")
|
||||
parser.add_argument("-p", "--profile", type=str, default='Profile',
|
||||
help="profile to use. Default:'Profile'")
|
||||
parser.add_argument("-p", "--profile", type=str, default=None,
|
||||
help="profile to use. Default:'Personal'")
|
||||
parser.add_argument("-t", "--passwordtype", type=int, choices=[1, 2, 3],
|
||||
help='''
|
||||
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
|
||||
"""
|
||||
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')
|
||||
else:
|
||||
private_key = privatekeygenerator()
|
||||
if self.profile == None:
|
||||
self.profile = 'Personal'
|
||||
self.config.add_section(self.profile)
|
||||
self.config.set(self.profile, 'private_key', private_key)
|
||||
chars = self.chars
|
||||
|
@ -90,6 +101,8 @@ class Util(object):
|
|||
pass_type = 1
|
||||
self.config.set(self.profile, 'chars', chars)
|
||||
self.config.set(self.profile, 'password_type', pass_type)
|
||||
if self.profile == 'Personal':
|
||||
self.config.set(self.profile, 'default', 1)
|
||||
self.writeconfig()
|
||||
print 'New profile is generated'
|
||||
self.config.read(self.filename)
|
||||
|
|
Loading…
Reference in New Issue