Skip to content

Commit 57d0e2e

Browse files
committed
style: Formatting and linting.
1 parent b3f94da commit 57d0e2e

File tree

8 files changed

+286
-116
lines changed

8 files changed

+286
-116
lines changed

src/pyddns/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
=====================================================================
44
55
**pyddns** is a Python package providing easy, programmable ddns clients
6-
for multiple services.
6+
for multiple services.
77
"""
88

99
from .services.duckdns_service import DuckDNS
1010
from .services.cloudflare_service import CloudflareDNS
1111

1212
__all__ = [
13-
'CloudflareDNS',
14-
'DuckDNS',
13+
"CloudflareDNS",
14+
"DuckDNS",
1515
]

src/pyddns/cache.py

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
"""
22
Storage Module
33
4-
This module provides a class for managing SQLite database operations specifically
4+
Provides a class for managing SQLite database operations specifically
55
for Dynamic DNS (DDNS) services. The `Storage` class handles the creation,
66
updating, and retrieval of domain records in a SQLite database.
77
"""
8+
89
import sqlite3
910
import logging
1011
from typing import Optional, Callable, Any, Tuple
1112
from datetime import datetime
1213

14+
1315
class Storage:
1416
"""
1517
A class to manage SQLite database operations for DDNS services.
@@ -18,15 +20,18 @@ class Storage:
1820
in a SQLite database.
1921
"""
2022

21-
def __init__(self, filename: str='py_ddns.db'):
23+
def __init__(self, filename: str = "py_ddns.db"):
2224
self.connection = sqlite3.connect(filename)
2325
self.cursor = self.connection.cursor()
2426

2527
self.create_tables()
2628

2729
@staticmethod
2830
def handle_sqlite_error(func: Callable) -> Callable:
29-
""" Decorator utilized to handle all errors invlovling the SQLite Database."""
31+
"""
32+
Decorator utilized to handle all errors involving the SQLite Database.
33+
"""
34+
3035
def wrapper(*args, **kwargs) -> Any:
3136

3237
try:
@@ -45,11 +50,12 @@ def wrapper(*args, **kwargs) -> Any:
4550
except sqlite3.IntegrityError as err:
4651
logging.error("SQLite Integrity Error: %s", err)
4752
raise
53+
4854
return wrapper
4955

5056
@handle_sqlite_error
5157
def create_tables(self) -> None:
52-
""" Method to create all SQLite tables utilized by pyddns """
58+
"""Method to create all SQLite tables utilized by pyddns"""
5359

5460
sql = """
5561
CREATE TABLE IF NOT EXISTS domains (
@@ -65,13 +71,17 @@ def create_tables(self) -> None:
6571
"""
6672
self.cursor.execute(sql)
6773
self.connection.commit()
68-
logging.debug("SQLite: Successfully verified that the domains table is present.")
74+
logging.debug(
75+
"SQLite: Successfully verified that the domains table is present."
76+
)
6977

7078
@handle_sqlite_error
7179
def drop_tables(self) -> None:
72-
""" Method to drop all SQLite tables utilized by pyddns """
80+
"""Method to drop all SQLite tables utilized by pyddns"""
7381

74-
logging.warning("one or more database tables have been requested to be dropped.")
82+
logging.warning(
83+
"one or more database tables have been requested to be dropped."
84+
)
7585

7686
sql = """
7787
DROP TABLE IF EXISTS domains;
@@ -83,39 +93,61 @@ def drop_tables(self) -> None:
8393

8494
@handle_sqlite_error
8595
def add_service(
86-
self, service_name: str, domain_name: str, current_ip: str, record_id: Optional[str] = None
87-
) -> None:
88-
""" Adds a service to the SQLite database and sets a created_at timestamp """
96+
self,
97+
service_name: str,
98+
domain_name: str,
99+
current_ip: str,
100+
record_id: Optional[str] = None,
101+
) -> None:
102+
"""
103+
Adds a service to the SQLite database and sets a created_at timestamp
104+
"""
89105

90106
sql = """
91107
INSERT INTO domains(service, domain_name, current_ip, record_id)
92108
VALUES(?, ?, ?, ?)
93109
"""
94-
self.cursor.execute(sql, (service_name, domain_name, current_ip, record_id))
110+
self.cursor.execute(
111+
sql, (service_name, domain_name, current_ip, record_id)
112+
)
95113
self.connection.commit()
96114
logging.debug(
97-
"SQLite: Adding service: %s, Domain: %s, IP: %s", service_name, domain_name, current_ip
115+
"SQLite: Adding service: %s, Domain: %s, IP: %s",
116+
service_name,
117+
domain_name,
118+
current_ip,
98119
)
99120
logging.info("SQLite: Sucessfully added %s to database.", service_name)
100121

101122
@handle_sqlite_error
102-
def update_ip(self, service_name: str, domain_name: str, current_ip: str) -> None:
103-
""" Updated the domain name's IP address in the SQLite database. """
123+
def update_ip(
124+
self, service_name: str, domain_name: str, current_ip: str
125+
) -> None:
126+
"""Updated the domain name's IP address in the SQLite database."""
104127

105128
sql = """
106129
UPDATE domains
107130
SET service = COALESCE(?, service),
108131
current_ip = COALESCE(?, current_ip),
109132
last_updated = CURRENT_TIMESTAMP
110-
WHERE domain_name = ?
133+
WHERE domain_name = ?
111134
"""
112135
self.cursor.execute(sql, (service_name, current_ip, domain_name))
113136
self.connection.commit()
114-
logging.info("SQLite: Updated %s on %s to %s", domain_name, service_name, current_ip)
137+
logging.info(
138+
"SQLite: Updated %s on %s to %s",
139+
domain_name,
140+
service_name,
141+
current_ip,
142+
)
115143

116144
@handle_sqlite_error
117-
def retrieve_record(self, domain_name: str) -> Optional[Tuple[str, datetime, str]]:
118-
""" Retrieves IP adress, last_updated, and record_id from SQLite databse if present. """
145+
def retrieve_record(
146+
self, domain_name: str
147+
) -> Optional[Tuple[str, datetime, str]]:
148+
"""
149+
Retrieves IP address, last_updated, and record_id from SQLite database
150+
"""
119151

120152
sql = """
121153
SELECT current_ip, last_updated, record_id FROM domains

src/pyddns/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
clients that interact with various DNS service providers. It includes methods
77
for obtaining the current public IP address and updating DNS records.
88
"""
9+
910
from abc import ABC, abstractmethod
1011
import logging
1112

1213
import requests
1314

15+
1416
class DDNSClient(ABC):
1517
"""
1618
An abstract base class for Dynamic DNS (DDNS) clients.
@@ -21,14 +23,14 @@ class DDNSClient(ABC):
2123
Methods:
2224
INHERITED: get_ip() -> str: Retrieves the current public IP address.
2325
ABSTRACT: update_dns(ip_address: str, record_name: str) -> None"
24-
"""
26+
"""
2527

2628
def get_ipv4(self) -> str:
27-
""" Obtains current IPv4 adress and returns as a str. """
29+
"""Obtains current IPv4 adress and returns as a str."""
2830

2931
logging.debug("Attempting to retrieve current public IP address.")
3032
try:
31-
response = requests.get('https://api.ipify.org', timeout=10)
33+
response = requests.get("https://api.ipify.org", timeout=10)
3234
response.raise_for_status()
3335

3436
logging.info("Current IPv4 is %s", response.text)
@@ -40,4 +42,6 @@ def get_ipv4(self) -> str:
4042

4143
@abstractmethod
4244
def update_dns(self, ip_address: str, record_name: str) -> None:
43-
""" Abstract Method to force all clients to have an update_dns method. """
45+
"""
46+
Abstract Method to force all clients to have an update_dns method.
47+
"""

src/pyddns/config.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
the application, promoting efficient resource management and consistent access
88
to configuration settings and data storage.
99
"""
10+
1011
from configparser import ConfigParser
1112
import logging
1213
import os
1314

15+
1416
class Config:
1517
"""
1618
A class to manage configuration settings using ConfigParser.
@@ -19,7 +21,7 @@ class Config:
1921
and provides methods to access the settings.
2022
"""
2123

22-
def __init__(self, config_file: str = 'py_ddns.ini') -> None:
24+
def __init__(self, config_file: str = "py_ddns.ini") -> None:
2325
"""
2426
Initializes the Config class and loads the configuration file.
2527
"""
@@ -32,25 +34,26 @@ def setup_logging(self) -> None:
3234
"""
3335
Sets up the logging configuration for the application.
3436
"""
35-
logging_level = self.config.get('Client_settings', 'logging_level')
37+
logging_level = self.config.get("Client_settings", "logging_level")
3638

37-
if logging_level.lower().strip() not in ['info', 'debug']:
39+
if logging_level.lower().strip() not in ["info", "debug"]:
3840
raise ValueError(
39-
f"Invalid logging level. Expected info or logging, got {logging_level}"
41+
"Invalid logging level."
42+
f"Expected info or logging, got {logging_level}"
4043
)
4144

42-
if logging_level.lower() == 'debug':
45+
if logging_level.lower() == "debug":
4346
level = logging.DEBUG
4447
else:
4548
level = logging.INFO
4649

4750
logging.basicConfig(
48-
level= level,
49-
format='%(asctime)s - %(levelname)s - %(message)s',
51+
level=level,
52+
format="%(asctime)s - %(levelname)s - %(message)s",
5053
handlers=[
51-
logging.FileHandler('py_ddns.log'),
52-
logging.StreamHandler()
53-
]
54+
logging.FileHandler("py_ddns.log"),
55+
logging.StreamHandler(),
56+
],
5457
)
5558
logging.info("Logging is set up, level = %s", logging_level.upper())
5659

@@ -60,7 +63,9 @@ def load_config(self) -> None:
6063
"""
6164

6265
if not os.path.exists(self.config_file):
63-
raise FileNotFoundError(f"Configuration file '{self.config_file}' not found.")
66+
raise FileNotFoundError(
67+
f"Configuration file '{self.config_file}' not found."
68+
)
6469

6570
self.config.read(self.config_file)
6671

src/pyddns/services/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
Services Module
3+
4+
This module provides integration for various DNS service providers
5+
"""

0 commit comments

Comments
 (0)