[cs615asa] [git commit] CS615 EBS-BACKUP; backup a directory into Elastic Block Storage (EBS) branch main updated. 7015fef81360a1392692e3afe4990978e31b91f7

Git Owner jschauma at stevens.edu
Sat Mar 20 19:38:23 EDT 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CS615 EBS-BACKUP; backup a directory into Elastic Block Storage (EBS)".

The branch, main has been updated
       via  7015fef81360a1392692e3afe4990978e31b91f7 (commit)
      from  198a237fe719892f470415d678daa81b468d700f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7015fef81360a1392692e3afe4990978e31b91f7
Author: Hayden Daly <hdaly1 at stevens.edu>
Date:   Thu Mar 18 16:47:22 2021 -0400

    Reorganized code structure + changed env parsing
    
    Co-authored-by: Noah Goldstein <ngoldstein51 at gmail.com>

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3e439ba
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+__pycache__/
+**/__pycache__/
+.vscode
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
deleted file mode 100644
index d6e456c..0000000
--- a/.vscode/settings.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-	"python.pythonPath": "/usr/bin/python3"
-}
\ No newline at end of file
diff --git a/pkg/__init__.py b/pkg/__init__.py
deleted file mode 100644
index fff8ea9..0000000
--- a/pkg/__init__.py
+++ /dev/null
@@ -1,3 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from .argument_parsing import parse_args
\ No newline at end of file
diff --git a/pkg/__pycache__/__init__.cpython-36.pyc b/pkg/__pycache__/__init__.cpython-36.pyc
deleted file mode 100644
index b4e857e..0000000
Binary files a/pkg/__pycache__/__init__.cpython-36.pyc and /dev/null differ
diff --git a/pkg/__pycache__/argument_parsing.cpython-36.pyc b/pkg/__pycache__/argument_parsing.cpython-36.pyc
deleted file mode 100644
index fd5a074..0000000
Binary files a/pkg/__pycache__/argument_parsing.cpython-36.pyc and /dev/null differ
diff --git a/src/.env b/src/.env
deleted file mode 100644
index 61e6652..0000000
--- a/src/.env
+++ /dev/null
@@ -1 +0,0 @@
-DEBUG=false
\ No newline at end of file
diff --git a/src/__init__.py b/src/__init__.py
new file mode 100644
index 0000000..4047644
--- /dev/null
+++ b/src/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+
+from .argument_parsing import parse_args
+from .env_parsing import parse_env 
\ No newline at end of file
diff --git a/src/__pycache__/__main__.cpython-36.pyc b/src/__pycache__/__main__.cpython-36.pyc
deleted file mode 100644
index 0bb7f8e..0000000
Binary files a/src/__pycache__/__main__.cpython-36.pyc and /dev/null differ
diff --git a/pkg/argument_parsing.py b/src/argument_parsing.py
similarity index 58%
rename from pkg/argument_parsing.py
rename to src/argument_parsing.py
index 9b6fb32..df613cc 100644
--- a/pkg/argument_parsing.py
+++ b/src/argument_parsing.py
@@ -1,4 +1,4 @@
-"""
+'''
 ebs-backup
 
 Usage:
@@ -11,32 +11,32 @@ Options:
   -r filter     Pass data through the given filter command on the remote
                 host before writing the data to the volume.
   -v volume-id  Use the given volume instead of creating a new one.
-"""
+'''
 import argparse
 import sys
 
 def parse_args(args):
   parser = argparse.ArgumentParser(
-      description="backup a directory into Elastic Block Storage (EBS)"
+      description='backup a directory into Elastic Block Storage (EBS)'
   )
   parser.add_argument(
-      "-l",
-      metavar="filter",
+      '-l',
+      metavar='filter',
       type=str,
-      help="Pass data through the given filter command on the local host before copying the\
-  data to the remote system.",
+      help='Pass data through the given filter command on the local host before copying the\
+  data to the remote system.',
   )
   parser.add_argument(
-      "-r",
-      metavar="filter",
+      '-r',
+      metavar='filter',
       type=str,
-      help="Pass data through the given filter command on the remote\
-                  host before writing the data to the volume.",
+      help='Pass data through the given filter command on the remote\
+                  host before writing the data to the volume.',
   )
   parser.add_argument(
-      "-v",
-      metavar="volume-id",
+      '-v',
+      metavar='volume-id',
       type=str,
-      help="Use the given volume instead of creating a new one.",
+      help='Use the given volume instead of creating a new one.',
   )
-  return parser.parse_args(args)
+  return vars(parser.parse_args(args))
diff --git a/src/env.py b/src/env.py
deleted file mode 100644
index fc0a4c7..0000000
--- a/src/env.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import os
-import environs
-
-# 031721 - 
-def env_parser():
-	env = environs.Env()
-	env.read_env()
-
-	debug = env.bool("DEBUG")
-	print(debug)
-
-env_parser()
\ No newline at end of file
diff --git a/src/env_parsing.py b/src/env_parsing.py
new file mode 100644
index 0000000..9710296
--- /dev/null
+++ b/src/env_parsing.py
@@ -0,0 +1,17 @@
+import os
+import environs
+
+def parse_env():
+	# See https://pypi.org/project/environs/ for more detail
+	env = environs.Env()
+	env.read_env()
+
+	env.str('AWS_CONFIG_FILE', None)
+	env.str('EC2_CERT', None)
+	env.str('EC2_HOME', None)
+	env.str('EC2_PRIVATE_KEY', None)
+	env.str('EBS_BACKUP_FLAGS_AWS', None)
+	env.str('EBS_BACKUP_FLAGS_SSH', None)
+	env.str('EBS_BACKUP_VERBOSE', None)
+
+	return env.dump()
diff --git a/src/main.py b/src/main.py
index 4f842c8..463ecdc 100644
--- a/src/main.py
+++ b/src/main.py
@@ -2,9 +2,12 @@ import boto3
 import sys
 import os
 
-sys.path.append('..')
-from pkg import parse_args
+from argument_parsing import parse_args
+from env_parsing import parse_env
 
 if __name__ == '__main__':
   args = parse_args(sys.argv[1:])
-  print(args)
\ No newline at end of file
+  env = parse_env()
+
+  print(args, env)
+  
\ No newline at end of file
diff --git a/test/README b/test/README
index b9e2e8d..5e52f93 100644
--- a/test/README
+++ b/test/README
@@ -2,7 +2,7 @@
 
 ## Usage
 
-To run all unit tests, run the following command:
+To run all unit tests, run the following command from within the test folder:
 
 ```sh
 $ python3 -m unittest -b
diff --git a/test/__init__.py b/test/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/test/__pycache__/__init__.cpython-36.pyc b/test/__pycache__/__init__.cpython-36.pyc
deleted file mode 100644
index 97b717f..0000000
Binary files a/test/__pycache__/__init__.cpython-36.pyc and /dev/null differ
diff --git a/test/__pycache__/test_parsing.cpython-36.pyc b/test/__pycache__/test_parsing.cpython-36.pyc
deleted file mode 100644
index 7dc3d08..0000000
Binary files a/test/__pycache__/test_parsing.cpython-36.pyc and /dev/null differ
diff --git a/test/test_parsing.py b/test/test_arg_parsing.py
similarity index 83%
rename from test/test_parsing.py
rename to test/test_arg_parsing.py
index 6ba3045..41da750 100644
--- a/test/test_parsing.py
+++ b/test/test_arg_parsing.py
@@ -4,13 +4,13 @@ import os
 from unittest.mock import patch
 
 sys.path.append('..')
-from pkg import parse_args
+from src import parse_args
 
 class ArgParseTest(unittest.TestCase):
     def test_parse_args_success(self):
         args = parse_args(['-l', 'hello_tests'])
         expected_args = { 'l': 'hello_tests', 'r': None, 'v': None }
-        self.assertEqual(vars(args), expected_args)
+        self.assertEqual(args, expected_args)
 
     def test_parse_failure(self):
         try:
diff --git a/test/test_env_parsing.py b/test/test_env_parsing.py
new file mode 100644
index 0000000..303b8e0
--- /dev/null
+++ b/test/test_env_parsing.py
@@ -0,0 +1,25 @@
+import unittest
+import sys
+import os
+from unittest.mock import patch
+
+sys.path.append('..')
+from src import parse_env
+
+class EnvParseTest(unittest.TestCase):
+    def test_parse_env_success(self):
+        expected_env = {
+            'EBS_BACKUP_FLAGS_SSH': None, 
+            'EC2_CERT': None, 
+            'EBS_BACKUP_FLAGS_AWS': None, 
+            'EBS_BACKUP_VERBOSE': None, 
+            'AWS_CONFIG_FILE': None, 
+            'EC2_PRIVATE_KEY': None, 
+            'EC2_HOME': None
+        }
+
+        env = parse_env()
+        self.assertEqual(env, expected_env)
+
+if __name__ == '__main__':
+    unittest.main()

-----------------------------------------------------------------------

Summary of changes:
 .gitignore                                      |   3 +++
 .vscode/settings.json                           |   3 ---
 pkg/__init__.py                                 |   3 ---
 pkg/__pycache__/__init__.cpython-36.pyc         | Bin 152 -> 0 bytes
 pkg/__pycache__/argument_parsing.cpython-36.pyc | Bin 1307 -> 0 bytes
 src/.env                                        |   1 -
 src/__init__.py                                 |   4 ++++
 src/__pycache__/__main__.cpython-36.pyc         | Bin 322 -> 0 bytes
 {pkg => src}/argument_parsing.py                |  30 ++++++++++++------------
 src/env.py                                      |  12 ----------
 src/env_parsing.py                              |  17 ++++++++++++++
 src/main.py                                     |   9 ++++---
 test/README                                     |   2 +-
 test/__init__.py                                |   0
 test/__pycache__/__init__.cpython-36.pyc        | Bin 127 -> 0 bytes
 test/__pycache__/test_parsing.cpython-36.pyc    | Bin 1008 -> 0 bytes
 test/{test_parsing.py => test_arg_parsing.py}   |   4 ++--
 test/test_env_parsing.py                        |  25 ++++++++++++++++++++
 18 files changed, 73 insertions(+), 40 deletions(-)
 create mode 100644 .gitignore
 delete mode 100644 .vscode/settings.json
 delete mode 100644 pkg/__init__.py
 delete mode 100644 pkg/__pycache__/__init__.cpython-36.pyc
 delete mode 100644 pkg/__pycache__/argument_parsing.cpython-36.pyc
 delete mode 100644 src/.env
 create mode 100644 src/__init__.py
 delete mode 100644 src/__pycache__/__main__.cpython-36.pyc
 rename {pkg => src}/argument_parsing.py (58%)
 delete mode 100644 src/env.py
 create mode 100644 src/env_parsing.py
 delete mode 100644 test/__init__.py
 delete mode 100644 test/__pycache__/__init__.cpython-36.pyc
 delete mode 100644 test/__pycache__/test_parsing.cpython-36.pyc
 rename test/{test_parsing.py => test_arg_parsing.py} (83%)
 create mode 100644 test/test_env_parsing.py


hooks/post-receive
-- 
CS615 EBS-BACKUP; backup a directory into Elastic Block Storage (EBS)


More information about the cs615asa mailing list