-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
58 lines (39 loc) · 1.29 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
58
"""
Provides basic funtions for LedgerTools.
See README.md for details.
@author: Etienne Monier <[email protected]>
@license: CC-BY-NC-SA
@since: 2020-07-24
"""
import sublime
import os.path
def get_settings():
# LedgerTools settings filename
settings_filename = "LedgerTools.sublime-settings"
# Load settings
return sublime.load_settings(settings_filename)
def is_ledger_file(view):
valid_ledger_file_ext = get_settings().get('valid_ledger_file_ext')
filename = view.file_name()
if filename is None:
return False
else:
_, ext = os.path.splitext(filename)
return ext in valid_ledger_file_ext
def get_definition_filename():
"""Checks if the definition filename specified in settings is valid.
Returns
-------
bool
True if the file name is valid, else False.
"""
definition_filename = get_settings().get('definition_filename')
# Checks that a filename is given
if definition_filename == "":
sublime.error_message("No ledger definition filename in settings.")
return False
# Check if filename exists
if not os.path.exists(definition_filename):
sublime.error_message("Ledger definition filename does not exists.")
return False
return definition_filename