-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
57 lines (43 loc) · 1.22 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import tempfile
from configparser import ConfigParser
def get_content_from_editor(current_content=None):
"""
Get the content from the default editor. If there is a current content, it
loads it within the editor.
:param current_content: The current item's content.
:type: str
:returns: The updated item's content.
:type: str
"""
t = tempfile.NamedTemporaryFile(delete=True)
if current_content:
t.write(current_content.encode('utf-8'))
t.flush()
try:
editor = os.environ['EDITOR']
except KeyError:
editor = 'nano'
subprocess.call([editor, t.name])
t.seek(0)
b_content = t.read()
t.close()
# TODO: what encoding is the editor using?
content = b_content.decode('utf-8')
return content
def get_configs(path):
config = ConfigParser()
config.read(path)
account_id = None
vault_name = None
if 'Credentials' in config:
credentials = config['Credentials']
account_id = credentials.get('account')
vault_name = credentials.get('vault')
return {
'account_id': account_id,
'vault_name': vault_name,
}