From 78cd06a80af31f430af90e8f8ee42a9a6a452cb0 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Thu, 7 Jan 2021 20:26:50 +0200
Subject: [PATCH] Address pre-commit issues.

---
 .pre-commit-config.yaml     |  1 +
 MANIFEST.in                 |  1 +
 check_s3_bucket/__init__.py | 31 ++++++++++++++++---------------
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 5f769c0..9cd5388 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -13,6 +13,7 @@ repos:
     rev: v0.14.3
     hooks:
       - id: detect-secrets
+        exclude: Pipfile\.lock
 
   - repo: https://github.com/adrienverge/yamllint
     rev: v1.25.0
diff --git a/MANIFEST.in b/MANIFEST.in
index e401aef..dc6dbf3 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,5 +1,6 @@
 recursive-include check_s3_bucket *.py
 exclude .pre-commit-config.yaml
+exclude .gitlab-ci.yml
 include *.rst
 include *.txt
 exclude .dockerignore
diff --git a/check_s3_bucket/__init__.py b/check_s3_bucket/__init__.py
index 0591dea..0b33964 100755
--- a/check_s3_bucket/__init__.py
+++ b/check_s3_bucket/__init__.py
@@ -9,18 +9,19 @@ from __future__ import (
 )
 import argparse
 import datetime
+import sys
 
 try:
     import botocore.session
     import botocore.exceptions
 except ImportError:
     print("Failed to import botocore.")
-    exit(3)
+    sys.exit(3)
 try:
     import pytz
 except ImportError:
     print("Failed to import pytz.")
-    exit(3)
+    sys.exit(3)
 
 __version__ = "0.2.4"
 NOW = datetime.datetime.now(pytz.utc)
@@ -44,7 +45,7 @@ def get_file_list(conn, bucket, prefix=""):
     return files
 
 
-def main():
+def main():  # noqa: C901
     """Main entrypoint."""
 
     # Parse command line arguments.
@@ -79,8 +80,8 @@ def main():
     )
     parser.add_argument(
         "size_critical_threshold",
-        help="""Critical threshold for the difference in size between the latest
-        2 files in percents (default to 50)""",
+        help="""Critical threshold for the difference in size between the
+        latest 2 files in percents (default to 50)""",
         default=50,
         type=int,
         nargs="?",
@@ -96,16 +97,16 @@ def main():
     except botocore.exceptions.BotoCoreError as exception:
         print("Failed to list the files in the S3 bucket.")
         print(str(exception))
-        exit(3)
+        sys.exit(3)
 
     if not files:
         print("No matching files in bucket.")
-        exit(2)
+        sys.exit(2)
 
     # Calculate the age of the latest file and if it's in the thresholds set.
     if files[0]["LastModified"] > NOW:
         print("Latest file is from the future, something is wrong.")
-        exit(3)
+        sys.exit(3)
     timedelta = files[0]["HoursSinceLastModified"]
     if timedelta > args.age_critical_threshold:
         print(
@@ -113,29 +114,29 @@ def main():
                 args.age_critical_threshold
             )
         )
-        exit(2)
+        sys.exit(2)
     elif timedelta > args.age_warning_threshold:
         print(
             "Last file modified is older than {} hours.".format(
                 args.age_warning_threshold
             )
         )
-        exit(1)
+        sys.exit(1)
 
     # Calculate the size ratio between the latest 2 files and check if
     # it's in the threshold set.
     if files[0]["Size"] == 0:
         print("Latest file is empty.")
-        exit(2)
+        sys.exit(2)
     elif len(files) == 1:
         print(
             """Found only 1 file in the bucket, can't calculate size
         difference."""
         )
-        exit(3)
+        sys.exit(3)
     elif files[1]["Size"] == 0:
         print("The last but 1 file is empty, can't calculate size difference.")
-        exit(3)
+        sys.exit(3)
 
     size_ratio = 100 * abs(
         (files[1]["Size"] - files[0]["Size"]) / files[1]["Size"]
@@ -146,14 +147,14 @@ def main():
                 size_ratio
             )
         )
-        exit(2)
+        sys.exit(2)
     if size_ratio > args.size_warning_threshold:
         print(
             "The size difference between the latest 2 file is {}%.".format(
                 size_ratio
             )
         )
-        exit(1)
+        sys.exit(1)
     else:
         print("File found and is within the thresholds set.")
 
-- 
GitLab