mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-03 07:16:12 +02:00
(#770) run black formatter on codebase for standardization
This commit is contained in:
parent
9664924096
commit
46c4c88231
24 changed files with 850 additions and 427 deletions
|
@ -13,16 +13,17 @@ from .util import UserAbort
|
|||
import yaml
|
||||
import logging
|
||||
import sys
|
||||
|
||||
if "win32" not in sys.platform:
|
||||
# readline is not included in Windows Active Python
|
||||
import readline
|
||||
import readline
|
||||
|
||||
DEFAULT_CONFIG_NAME = 'jrnl.yaml'
|
||||
DEFAULT_JOURNAL_NAME = 'journal.txt'
|
||||
DEFAULT_JOURNAL_KEY = 'default'
|
||||
XDG_RESOURCE = 'jrnl'
|
||||
DEFAULT_CONFIG_NAME = "jrnl.yaml"
|
||||
DEFAULT_JOURNAL_NAME = "journal.txt"
|
||||
DEFAULT_JOURNAL_KEY = "default"
|
||||
XDG_RESOURCE = "jrnl"
|
||||
|
||||
USER_HOME = os.path.expanduser('~')
|
||||
USER_HOME = os.path.expanduser("~")
|
||||
|
||||
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
|
||||
CONFIG_FILE_PATH = os.path.join(CONFIG_PATH, DEFAULT_CONFIG_NAME)
|
||||
|
@ -43,21 +44,20 @@ def module_exists(module_name):
|
|||
else:
|
||||
return True
|
||||
|
||||
|
||||
default_config = {
|
||||
'version': __version__,
|
||||
'journals': {
|
||||
DEFAULT_JOURNAL_KEY: JOURNAL_FILE_PATH
|
||||
},
|
||||
'editor': os.getenv('VISUAL') or os.getenv('EDITOR') or "",
|
||||
'encrypt': False,
|
||||
'template': False,
|
||||
'default_hour': 9,
|
||||
'default_minute': 0,
|
||||
'timeformat': "%Y-%m-%d %H:%M",
|
||||
'tagsymbols': '@',
|
||||
'highlight': True,
|
||||
'linewrap': 79,
|
||||
'indent_character': '|',
|
||||
"version": __version__,
|
||||
"journals": {DEFAULT_JOURNAL_KEY: JOURNAL_FILE_PATH},
|
||||
"editor": os.getenv("VISUAL") or os.getenv("EDITOR") or "",
|
||||
"encrypt": False,
|
||||
"template": False,
|
||||
"default_hour": 9,
|
||||
"default_minute": 0,
|
||||
"timeformat": "%Y-%m-%d %H:%M",
|
||||
"tagsymbols": "@",
|
||||
"highlight": True,
|
||||
"linewrap": 79,
|
||||
"indent_character": "|",
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,13 +70,18 @@ def upgrade_config(config):
|
|||
for key in missing_keys:
|
||||
config[key] = default_config[key]
|
||||
save_config(config)
|
||||
print(f"[Configuration updated to newest version at {CONFIG_FILE_PATH}]", file=sys.stderr)
|
||||
print(
|
||||
f"[Configuration updated to newest version at {CONFIG_FILE_PATH}]",
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
|
||||
def save_config(config):
|
||||
config['version'] = __version__
|
||||
with open(CONFIG_FILE_PATH, 'w') as f:
|
||||
yaml.safe_dump(config, f, encoding='utf-8', allow_unicode=True, default_flow_style=False)
|
||||
config["version"] = __version__
|
||||
with open(CONFIG_FILE_PATH, "w") as f:
|
||||
yaml.safe_dump(
|
||||
config, f, encoding="utf-8", allow_unicode=True, default_flow_style=False
|
||||
)
|
||||
|
||||
|
||||
def load_or_install_jrnl():
|
||||
|
@ -84,17 +89,27 @@ def load_or_install_jrnl():
|
|||
If jrnl is already installed, loads and returns a config object.
|
||||
Else, perform various prompts to install jrnl.
|
||||
"""
|
||||
config_path = CONFIG_FILE_PATH if os.path.exists(CONFIG_FILE_PATH) else CONFIG_FILE_PATH_FALLBACK
|
||||
config_path = (
|
||||
CONFIG_FILE_PATH
|
||||
if os.path.exists(CONFIG_FILE_PATH)
|
||||
else CONFIG_FILE_PATH_FALLBACK
|
||||
)
|
||||
if os.path.exists(config_path):
|
||||
log.debug('Reading configuration from file %s', config_path)
|
||||
log.debug("Reading configuration from file %s", config_path)
|
||||
config = util.load_config(config_path)
|
||||
|
||||
try:
|
||||
upgrade.upgrade_jrnl_if_necessary(config_path)
|
||||
except upgrade.UpgradeValidationException:
|
||||
print("Aborting upgrade.", file=sys.stderr)
|
||||
print("Please tell us about this problem at the following URL:", file=sys.stderr)
|
||||
print("https://github.com/jrnl-org/jrnl/issues/new?title=UpgradeValidationException", file=sys.stderr)
|
||||
print(
|
||||
"Please tell us about this problem at the following URL:",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(
|
||||
"https://github.com/jrnl-org/jrnl/issues/new?title=UpgradeValidationException",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print("Exiting.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -102,7 +117,7 @@ def load_or_install_jrnl():
|
|||
|
||||
return config
|
||||
else:
|
||||
log.debug('Configuration file not found, installing jrnl...')
|
||||
log.debug("Configuration file not found, installing jrnl...")
|
||||
try:
|
||||
config = install()
|
||||
except KeyboardInterrupt:
|
||||
|
@ -112,25 +127,32 @@ def load_or_install_jrnl():
|
|||
|
||||
def install():
|
||||
if "win32" not in sys.platform:
|
||||
readline.set_completer_delims(' \t\n;')
|
||||
readline.set_completer_delims(" \t\n;")
|
||||
readline.parse_and_bind("tab: complete")
|
||||
readline.set_completer(autocomplete)
|
||||
|
||||
# Where to create the journal?
|
||||
path_query = f'Path to your journal file (leave blank for {JOURNAL_FILE_PATH}): '
|
||||
path_query = f"Path to your journal file (leave blank for {JOURNAL_FILE_PATH}): "
|
||||
journal_path = input(path_query).strip() or JOURNAL_FILE_PATH
|
||||
default_config['journals'][DEFAULT_JOURNAL_KEY] = os.path.expanduser(os.path.expandvars(journal_path))
|
||||
default_config["journals"][DEFAULT_JOURNAL_KEY] = os.path.expanduser(
|
||||
os.path.expandvars(journal_path)
|
||||
)
|
||||
|
||||
path = os.path.split(default_config['journals'][DEFAULT_JOURNAL_KEY])[0] # If the folder doesn't exist, create it
|
||||
path = os.path.split(default_config["journals"][DEFAULT_JOURNAL_KEY])[
|
||||
0
|
||||
] # If the folder doesn't exist, create it
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# Encrypt it?
|
||||
encrypt = util.yesno("Do you want to encrypt your journal? You can always change this later", default=False)
|
||||
encrypt = util.yesno(
|
||||
"Do you want to encrypt your journal? You can always change this later",
|
||||
default=False,
|
||||
)
|
||||
if encrypt:
|
||||
default_config['encrypt'] = True
|
||||
default_config["encrypt"] = True
|
||||
print("Journal will be encrypted.", file=sys.stderr)
|
||||
|
||||
save_config(default_config)
|
||||
|
@ -138,7 +160,7 @@ def install():
|
|||
|
||||
|
||||
def autocomplete(text, state):
|
||||
expansions = glob.glob(os.path.expanduser(os.path.expandvars(text)) + '*')
|
||||
expansions = glob.glob(os.path.expanduser(os.path.expandvars(text)) + "*")
|
||||
expansions = [e + "/" if os.path.isdir(e) else e for e in expansions]
|
||||
expansions.append(None)
|
||||
return expansions[state]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue