Completed
Push — master ( 24f910...5df540 )
by Chad
13:43
created

diff_classifier.aws.partition_and_store()   B

Complexity

Conditions 2

Size

Total Lines 28
Code Lines 10

Duplication

Lines 28
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 10
dl 28
loc 28
rs 8.8571
c 0
b 0
f 0
cc 2
nop 3
1
import os
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
# import diff_classifier.imagej as ij
3
import boto3
0 ignored issues
show
introduced by
Unable to import 'boto3'
Loading history...
4
import os.path as op
0 ignored issues
show
Unused Code introduced by
Unused os.path imported as op
Loading history...
introduced by
standard import "import os.path as op" should be placed before "import boto3"
Loading history...
5
6
7
def download_s3(remote_fname, local_fname, bucket_name="ccurtis7.pup"):
8
    """
9
    Download a file from S3 to our local file-system
10
11
    Parameters
12
    ----------
13
    remote_fname: string
14
        Name of remote file in S3 bucket.
15
    local_fname: string
16
        Desired name to be stored on local computer.
17
    bucket_name: string
18
        Bucket name on S3.
19
    """
20
    if not os.path.exists(local_fname):
21
        s3 = boto3.resource('s3')
0 ignored issues
show
Coding Style Naming introduced by
The name s3 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
22
        b = s3.Bucket(bucket_name)
0 ignored issues
show
Coding Style Naming introduced by
The name b does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
23
        b.download_file(remote_fname, local_fname)
24
25
26
def upload_s3(local_fname, remote_fname, bucket_name="ccurtis7.pup"):
27
    """
28
    Upload a file from local file-system to S3.
29
30
    Parameters
31
    ----------
32
    local_fname: string
33
        Name of local file stored on computer.
34
    remote_fname: string
35
        Desired name to be stored in S3 bucket.
36
    bucket_name: string
37
        Bucket name on S3.
38
    """
39
40
    s3 = boto3.resource('s3')
0 ignored issues
show
Coding Style Naming introduced by
The name s3 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
41
    b = s3.Bucket(bucket_name)
0 ignored issues
show
Coding Style Naming introduced by
The name b does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
42
    b.upload_file(local_fname, remote_fname)
43
44
45
# def partition_and_store(remote_fname, local_dir, bucket_name="ccurtis7.pup"):
46
#     """
47
#     Download image from S3, partition, and upload partitions to S3.
48
49
#     Parameters
50
#     ----------
51
#     remote_fname: string
52
#         Target filename in S3 bucket.
53
#     local_dir: string
54
#         Local directory to store downloaded file.
55
#     bucket_name: string
56
#         Bucket name on S3.
57
58
#     Returns
59
#     -------
60
#     remote_names: list of strings.
61
#         Names of partitioned images in S3.
62
#     """
63
#     remote_dir, remote_file = op.split(remote_fname)
64
#     download_s3(remote_fname, op.join(local_dir, remote_file))
65
#     names = ij.partition_im(op.join(local_dir, remote_file))
66
67
#     remote_names = []
68
#     for file in names:
69
#         local_file = op.split(file)[1]
70
#         upload_s3(op.join(local_dir, local_file), op.join(remote_dir, local_file))
71
#         remote_names.append(op.join(remote_dir, local_file))
72
#     return remote_names
73