|
2 | 2 |
|
3 | 3 | import argparse |
4 | 4 | import configparser |
5 | | - |
6 | | -# import json |
7 | 5 | import logging |
8 | 6 | import os |
9 | 7 | import platform |
|
12 | 10 | import time |
13 | 11 | import webbrowser |
14 | 12 | from datetime import datetime |
15 | | -from functools import partial |
16 | 13 | from pathlib import Path |
17 | 14 | from queue import Queue |
18 | 15 | from typing import List, Literal |
19 | 16 | from urllib.parse import ParseResult, urlparse |
20 | 17 |
|
21 | 18 | import requests |
22 | | - |
23 | | -# from multiprocessing import Process, Queue |
24 | 19 | from rich.prompt import Confirm |
25 | 20 |
|
26 | | -import murfey.client.rsync |
27 | 21 | import murfey.client.update |
28 | 22 | import murfey.client.watchdir |
29 | 23 | import murfey.client.websocket |
30 | 24 | from murfey.client.customlogging import CustomHandler, DirectableRichHandler |
31 | 25 | from murfey.client.instance_environment import MurfeyInstanceEnvironment |
32 | 26 | from murfey.client.tui.app import MurfeyTUI |
33 | 27 | from murfey.client.tui.status_bar import StatusBar |
34 | | -from murfey.util import _get_visit_list |
35 | | - |
36 | | -# from asyncio import Queue |
37 | | - |
38 | | - |
39 | | -# from rich.prompt import Prompt |
40 | | - |
| 28 | +from murfey.util.client import _get_visit_list, authorised_requests, read_config |
41 | 29 |
|
42 | 30 | log = logging.getLogger("murfey.client") |
43 | 31 |
|
44 | | - |
45 | | -def read_config() -> configparser.ConfigParser: |
46 | | - config = configparser.ConfigParser() |
47 | | - try: |
48 | | - mcch = os.environ.get("MURFEY_CLIENT_CONFIG_HOME") |
49 | | - murfey_client_config_home = Path(mcch) if mcch else Path.home() |
50 | | - with open(murfey_client_config_home / ".murfey") as configfile: |
51 | | - config.read_file(configfile) |
52 | | - except FileNotFoundError: |
53 | | - log.warning( |
54 | | - f"Murfey client configuration file {murfey_client_config_home / '.murfey'} not found" |
55 | | - ) |
56 | | - if "Murfey" not in config: |
57 | | - config["Murfey"] = {} |
58 | | - return config |
59 | | - |
60 | | - |
61 | | -token = read_config()["Murfey"].get("token", "") |
62 | | - |
63 | | -requests.get = partial(requests.get, headers={"Authorization": f"Bearer {token}"}) |
64 | | -requests.post = partial(requests.post, headers={"Authorization": f"Bearer {token}"}) |
65 | | -requests.delete = partial(requests.delete, headers={"Authorization": f"Bearer {token}"}) |
| 32 | +requests.get, requests.post, requests.put, requests.delete = authorised_requests() |
66 | 33 |
|
67 | 34 |
|
68 | 35 | def write_config(config: configparser.ConfigParser): |
|
0 commit comments