Set limit on migration
This commit is contained in:
parent
a4b6c35784
commit
f621440116
1 changed files with 27 additions and 23 deletions
|
@ -696,30 +696,33 @@ class NcPasswordClient:
|
||||||
'''Delete a passwords folder'''
|
'''Delete a passwords folder'''
|
||||||
print(json.dumps(self.nc.delete_passwords_folder(name), indent=2))
|
print(json.dumps(self.nc.delete_passwords_folder(name), indent=2))
|
||||||
|
|
||||||
def migrate_pass(self):
|
def migrate_pass(self, limit=-1):
|
||||||
'''Migrate password store to Nextcloud pass'''
|
'''Migrate password store to Nextcloud pass'''
|
||||||
store = passpy.store.Store()
|
store = passpy.store.Store()
|
||||||
|
count = 0
|
||||||
for item in store.find(''):
|
for item in store.find(''):
|
||||||
obj = {
|
if limit > -1 and limit > count:
|
||||||
"label": os.path.basename(item),
|
obj = {
|
||||||
}
|
"label": os.path.basename(item),
|
||||||
folder = os.path.dirname(item)
|
}
|
||||||
if folder != '':
|
folder = os.path.dirname(item)
|
||||||
obj['folder'] = folder
|
if folder != '':
|
||||||
raw_values = store.get_key(item).split('\n')
|
obj['folder'] = folder
|
||||||
obj['password'] = raw_values[0]
|
raw_values = store.get_key(item).split('\n')
|
||||||
raw_values.pop(0)
|
obj['password'] = raw_values[0]
|
||||||
for line in raw_values:
|
raw_values.pop(0)
|
||||||
if ': ' in line:
|
for line in raw_values:
|
||||||
split_line = line.split(': ')
|
if ': ' in line:
|
||||||
field = split_line[0]
|
split_line = line.split(': ')
|
||||||
value = split_line[1]
|
field = split_line[0]
|
||||||
else:
|
value = split_line[1]
|
||||||
field = line
|
else:
|
||||||
value = ''
|
field = line
|
||||||
if field != '' and value != '':
|
value = ''
|
||||||
obj[field] = value
|
if field != '' and value != '':
|
||||||
print(json.dumps(self.nc.create_password(obj), indent=2))
|
obj[field] = value
|
||||||
|
print(json.dumps(self.nc.create_password(obj), indent=2))
|
||||||
|
count += 1
|
||||||
|
|
||||||
def _init_log(self):
|
def _init_log(self):
|
||||||
''' Initialize log object '''
|
''' Initialize log object '''
|
||||||
|
@ -864,11 +867,12 @@ def delete_passwords_folder(ctx, name):
|
||||||
ctx.obj['NcPasswordClient'].delete_passwords_folder(name)
|
ctx.obj['NcPasswordClient'].delete_passwords_folder(name)
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
@click.option('--limit', '-l', default=-1, help='Maximun number of passwords to migrate. -1 for unlimited.')
|
||||||
@click_config_file.configuration_option()
|
@click_config_file.configuration_option()
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def migrate_pass(ctx):
|
def migrate_pass(ctx, limit):
|
||||||
'''Migrate password store passwords to Nextcloud Passwords'''
|
'''Migrate password store passwords to Nextcloud Passwords'''
|
||||||
ctx.obj['NcPasswordClient'].migrate_pass()
|
ctx.obj['NcPasswordClient'].migrate_pass(limit)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli(obj={})
|
cli(obj={})
|
||||||
|
|
Loading…
Reference in a new issue