Skip to content

Commit

Permalink
chore(qbtools): refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
buroa committed Oct 2, 2024
1 parent a18b540 commit 8c15d06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ FROM base as final
WORKDIR /app
COPY --from=pip /install /usr/local
COPY --from=app /app .
COPY config.yaml /config/config.yaml
ENTRYPOINT ["python3", "qbtools.py"]
19 changes: 11 additions & 8 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
---
trackers:
- name: iptorrents
urls:
- bgp.technology
- empirehost.me
- stackoverflow.tech
required_seed_ratio: 1.05
required_seed_days: 14.5
trackers: {}

# Example:
# trackers:
# - name: iptorrents
# urls:
# - bgp.technology
# - empirehost.me
# - stackoverflow.tech
# required_seed_ratio: 1.05
# required_seed_days: 14.5
26 changes: 15 additions & 11 deletions qbtools/qbtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

logger = logging.getLogger(__name__)


def add_default_args(parser):
parser.add_argument(
"-c", "--config",
Expand Down Expand Up @@ -52,7 +53,7 @@ def load_commands(subparsers):

def qbit_client(app):
if not app.server or not app.port:
logger.error("Server and port must be specified.")
logger.error("Server and port must be specified")
sys.exit(1)

client = qbittorrentapi.Client(
Expand All @@ -63,25 +64,28 @@ def qbit_client(app):

try:
client.auth_log_in()
except qbittorrentapi.APIConnectionError:
logger.error("Error connecting to qBittorrent", exc_info=True)
sys.exit(1)
except qbittorrentapi.LoginFailed:
logger.error("Login failed", exc_info=True)
logger.error("Login failed to qBittorrent", exc_info=True)
sys.exit(1)

return client
else:
return client


def get_config(app):
config = {}

try:
with open(app.config, "r") as stream:
config = yaml.safe_load(stream)
except FileNotFoundError:
logger.debug("Configuration file not found", exc_info=True) # Not an error
logger.error(f"Configuration file not found: {app.config}", exc_info=True)
sys.exit(1)
except yaml.YAMLError:
logger.error("Error parsing configuration file", exc_info=True)

return config
logger.error(f"Error parsing configuration file: {app.config}", exc_info=True)
sys.exit(1)
else:
return config


def main():
Expand Down Expand Up @@ -113,7 +117,7 @@ def main():
except Exception:
logger.error(f"Error executing command: {app.command}", exc_info=True)
sys.exit(1)
else:
finally:
app.client.auth_log_out()

if __name__ == "__main__":
Expand Down

0 comments on commit 8c15d06

Please sign in to comment.