GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Pull Request — master (#28)
by
unknown
01:57
created

b2blaze.models.b2_file   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Test Coverage

Coverage 18.75%

Importance

Changes 0
Metric Value
eloc 76
dl 0
loc 145
ccs 12
cts 64
cp 0.1875
rs 10
c 0
b 0
f 0
wmc 15

7 Methods

Rating   Name   Duplication   Size   Complexity  
A B2File.__init__() 0 30 1
A B2File.get_versions() 0 28 3
A B2File.url() 0 4 1
A B2File.delete_all_versions() 0 30 4
A B2File.download() 0 7 2
A B2File.hide() 0 12 2
A B2File.delete() 0 11 2
1
"""
2
Copyright George Sibble 2018
3
"""
4 1
from io import BytesIO
5 1
from ..utilities import b2_url_encode, b2_url_decode, decode_error
0 ignored issues
show
Unused Code introduced by
Unused b2_url_decode imported from utilities
Loading history...
Unused Code introduced by
Unused decode_error imported from utilities
Loading history...
6 1
from ..b2_exceptions import B2Exception
7 1
from ..api import API
8
9 1
class B2File(object):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
best-practice introduced by
Too many instance attributes (11/7)
Loading history...
10
    """
11
12
    """
13 1
    def __init__(self, connector, parent_list, fileId, fileName, contentSha1, contentLength, contentType,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
best-practice introduced by
Too many arguments (11/5)
Loading history...
Unused Code introduced by
The argument args seems to be unused.
Loading history...
Unused Code introduced by
The argument kwargs seems to be unused.
Loading history...
14
                 fileInfo, action, uploadTimestamp, *args, **kwargs):
15
        """
16
17
        :param connector:
18
        :param parent_list:
19
        :param fileId:
20
        :param fileName:
21
        :param contentSha1:
22
        :param contentLength:
23
        :param contentType:
24
        :param fileInfo:
25
        :param action:
26
        :param uploadTimestamp:
27
        :param args:
28
        :param kwargs:
29
        """
30
        self.file_id = fileId
31
        # self.file_name_decoded = b2_url_decode(fileName)
32
         #TODO:  Find out if this is necessary
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
33
        self.file_name = fileName
34
        self.content_sha1 = contentSha1
35
        self.content_length = contentLength
36
        self.content_type = contentType
37
        self.file_info = fileInfo
38
        self.action = action
39
        self.uploadTimestamp = uploadTimestamp
0 ignored issues
show
Coding Style Naming introduced by
The name uploadTimestamp does not conform to the attribute 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...
40
        self.connector = connector
41
        self.parent_list = parent_list
42
        self.deleted = False
43
44 1
    def get_versions(self, limit=None): 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
45
        """ Fetch list of all versions of the current file.
46
            Params:
47
                limit:              (int) Limit number of results returned (optional, default 10000)
48
49
            Returns:
50
                file_versions       (list) B2FileObject of all file versions
51
        """
52
        bucket_id = self.parent_list.bucket.bucket_id
53
54
        path = API.list_file_versions
55
        file_versions = []
56
        params = {
57
            'bucketId': bucket_id,
58
            'maxFileCount': limit or 10000,
59
            'startFileId': self.file_id,
60
            'startFileName': self.file_name,
61
        }
62
63
        response = self.connector.make_request(path=path, method='post', params=params)
64
        if response.status_code == 200:
65
            files_json = response.json()
66
            for file_json in files_json['files']:
67
                new_file = B2File(connector=self.connector, parent_list=self, **file_json)
68
                file_versions.append(new_file)
69
        else:
70
            raise B2Exception.parse(response)
71
        return file_versions
72
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
73
74 1
    def hide(self):
75
        """ Soft-delete a file (hide it from files list, but previous versions are saved.) """
76
        path = API.delete_file
77
        params = {
78
            'bucketId': self.parent_list.bucket.bucket_id,
79
            'fileName': b2_url_encode(self.file_name)
80
        }
81
        response = self.connector.make_request(path=path, method='post', params=params)
82
        if response.status_code == 200:
83
            self.deleted = True
84
        else:
85
            raise B2Exception.parse(response)
86
87
88 1
    def delete_all_versions(self, confirm=False):
89
        """ Delete completely all versions of a file. 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
90
            ** NOTE THAT THIS CAN BE VERY EXPENSIVE IN TERMS OF YOUR API LIMITS **
91
            Each call to delete_all_versions will result in multiple API calls: 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
92
                One API call per file version to be deleted, per file.
93
            1. Call '/b2_list_file_versions' to get file versions
94
            2. Call '/b2_delete_file_version' once for each version of the file
95
96
            This means: if you have 10 files with 50 versions each and call delete_all_versions, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
97
            you will spend (10 + 1) x 50 == 550 API calls against your BackBlaze b2 API limit.
98
99
            ** You have been warned! BE CAREFUL!!! **
100
        """
101
        print(self.delete_all_versions.__name__, self.delete_all_versions.__doc__) # Print warnings at call time.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
102
103
        # Confirm deletion
104
        if not confirm:
105
            print('To call this function, use delete_all_versions(confirm=True)')
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after print.
Loading history...
106
            return False
107
108
        versions = self.get_versions()
109
110
        version_count = len(versions)
111
        if not version_count > 0:
112
            print('No file versions')
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after print.
Loading history...
113
        else:
114
            print(version_count, 'file versions')
115
            for count, v in enumerate(versions):
0 ignored issues
show
Coding Style Naming introduced by
The name v 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...
116
                print('deleting [{}/{}]'.format(count + 1 , version_count))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after print.
Loading history...
Coding Style introduced by
No space allowed before comma
Loading history...
117
                v.delete()
118
119
120 1
    def delete(self):
121
        """ Delete a file version (Does not delete entire file history: only most recent version) """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
122
        path = API.delete_file_version
123
        params = {
124
            'fileId': self.file_id,
125
            'fileName': b2_url_encode(self.file_name)
126
        }
127
        response = self.connector.make_request(path=path, method='post', params=params)
128
        if not response.status_code == 200:
129
            raise B2Exception.parse(response)
130
        self.deleted = True
131
132
133 1
    def download(self):
134
        """ Download latest file version """
135
        response = self.connector.download_file(file_id=self.file_id)
136
        if response.status_code == 200:
137
            return BytesIO(response.content)
138
        else:
139
            raise B2Exception.parse(response)
140
141 1
    @property
142
    def url(self):
143
        """ Return file download URL """
144
        return self.connector.download_url + '?fileId=' + self.file_id
145