Skip to content

Commit 36e76a6

Browse files
committed
Eliminated unnecessary reraising and some commented code.
1 parent dacc066 commit 36e76a6

File tree

10 files changed

+75
-190
lines changed

10 files changed

+75
-190
lines changed

gdrivefs/cache/cache_registry.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ def remove(self, resource_name, key, cleanup_pretrigger=None):
5454
(resource_name, key, type(cleanup_pretrigger)))
5555

5656
with CacheRegistry.__rlock:
57-
try:
58-
old_tuple = self.__cache[resource_name][key]
59-
except:
60-
raise
57+
old_tuple = self.__cache[resource_name][key]
6158

62-
self.__cleanup_entry(resource_name, key, True,
63-
cleanup_pretrigger=cleanup_pretrigger)
59+
self.__cleanup_entry(
60+
resource_name,
61+
key,
62+
True,
63+
cleanup_pretrigger=cleanup_pretrigger)
6464

6565
return old_tuple[0]
6666

gdrivefs/change.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,15 @@ def __apply_change(self, change_id, change_tuple):
137137
_logger.debug("Removing all trace of entry with ID [%s] "
138138
"(apply_change).", entry_id)
139139

140-
try:
141-
PathRelations.get_instance().remove_entry_all(entry_id)
142-
except:
143-
_logger.exception("There was a problem remove entry with ID "
144-
"[%s] from the caches.", entry_id)
145-
raise
140+
PathRelations.get_instance().remove_entry_all(entry_id)
146141

147142
# If it wasn't deleted, add it back.
148143

149144
_logger.debug("Registering changed entry with ID [%s].", entry_id)
150145

151146
if is_visible:
152147
path_relations = PathRelations.get_instance()
153-
154-
try:
155-
path_relations.register_entry(entry)
156-
except:
157-
_logger.exception("Could not register changed entry with "
158-
"ID [%s] with path-relations cache.",
159-
entry_id)
160-
raise
148+
path_relations.register_entry(entry)
161149

162150
_instance = None
163151
def get_change_manager():

gdrivefs/conf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ class Conf(object):
5050

5151
@staticmethod
5252
def get(key):
53-
try:
54-
return Conf.__dict__[key]
55-
except:
56-
_logger.exception("Could not retrieve config value with key [%s].",
57-
key)
58-
raise
53+
return Conf.__dict__[key]
5954

6055
@staticmethod
6156
def set(key, value):

gdrivefs/gdfs/displaced_file.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,17 @@ def deposit_file(self, mime_type):
3535

3636
gd = get_gdrive()
3737

38-
try:
39-
result = gd.download_to_local(
40-
self.__filepath,
41-
self.__normalized_entry,
42-
mime_type)
43-
(length, cache_fault) = result
44-
except:
45-
_logger.exception("Could not localize displaced file with entry"
46-
"having ID [%s].", self.__normalized_entry.id)
47-
raise
38+
result = gd.download_to_local(
39+
self.__filepath,
40+
self.__normalized_entry,
41+
mime_type)
42+
43+
(length, cache_fault) = result
4844

4945
_logger.debug("Displaced entry [%s] deposited to [%s] with length "
5046
"(%d).", self.__normalized_entry, self.__filepath, length)
5147

52-
try:
53-
return self.get_stub(mime_type, length, self.__filepath)
54-
except:
55-
_logger.exception("Could not build stub for [%s].",
56-
self.__normalized_entry)
57-
raise
48+
return self.get_stub(mime_type, length, self.__filepath)
5849

5950
def get_stub(self, mime_type, file_size=0, file_path=None):
6051
"""Return the content for an info ("stub") file."""

gdrivefs/gdfs/fsutility.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,9 @@ def split_path(filepath_original, pathresolver_cb):
117117
"""
118118

119119
# Remove any export-type that this file-path might've been tagged with.
120-
121-
try:
122-
(filepath, mime_type) = strip_export_type(filepath_original)
123-
except:
124-
_logger.exception("Could not process path [%s] for export-type.",
125-
filepath_original)
126-
raise
127-
128-
# log.debug("File-path [%s] split into filepath [%s] and mime_type "
129-
# "[%s]." % (filepath_original, filepath, mime_type))
120+
(filepath, mime_type) = strip_export_type(filepath_original)
130121

131122
# Split the file-path into a path and a filename.
132-
133123
(path, filename) = split(filepath)
134124

135125
# Lookup the file, as it was listed, in our cache.
@@ -144,18 +134,12 @@ def split_path(filepath_original, pathresolver_cb):
144134
raise GdNotFoundError()
145135

146136
if not path_resolution:
147-
# log.debug("Path [%s] does not exist for split." % (path))
148137
raise GdNotFoundError()
149138

150139
(parent_entry, parent_clause) = path_resolution
151140

152141
is_hidden = (filename[0] == '.') if filename else False
153142

154-
# log.debug("File-path [%s] split into parent with ID [%s], path [%s], "
155-
# "unverified filename [%s], mime-type [%s], and is_hidden [%s]." %
156-
# (filepath_original, parent_entry.id, path, filename,
157-
# mime_type, is_hidden))
158-
159143
return (parent_clause, path, filename, mime_type, is_hidden)
160144

161145
def split_path_nolookups(filepath_original):
@@ -164,16 +148,9 @@ def split_path_nolookups(filepath_original):
164148
"""
165149

166150
# Remove any export-type that this file-path might've been tagged with.
167-
168-
try:
169-
(filepath, mime_type) = strip_export_type(filepath_original)
170-
except:
171-
_logger.exception("Could not process path [%s] for export-type.",
172-
filepath_original)
173-
raise
151+
(filepath, mime_type) = strip_export_type(filepath_original)
174152

175153
# Split the file-path into a path and a filename.
176-
177154
(path, filename) = split(filepath)
178155

179156
# We don't remove the period, if we will mark it as hidden, as appropriate.

gdrivefs/gdfs/gdfuse.py

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -100,32 +100,19 @@ class _GdfsMixin(object):
100100
"""The main filesystem class."""
101101

102102
def __register_open_file(self, fh, path, entry_id):
103-
104103
with self.fh_lock:
105104
self.open_files[fh] = (entry_id, path)
106105

107106
def __deregister_open_file(self, fh):
108-
109107
with self.fh_lock:
110-
try:
111-
file_info = self.open_files[fh]
112-
except:
113-
_logger.exception("Could not deregister invalid file-handle "
114-
"(%d).", fh)
115-
raise
108+
file_info = self.open_files[fh]
116109

117110
del self.open_files[fh]
118111
return file_info
119112

120113
def __get_open_file(self, fh):
121-
122114
with self.fh_lock:
123-
try:
124-
return self.open_files[fh]
125-
except:
126-
_logger.exception("Could not retrieve on invalid file-handle "
127-
"(%d).", fh)
128-
raise
115+
return self.open_files[fh]
129116

130117
def __build_stat_from_entry(self, entry):
131118
(uid, gid, pid) = fuse_get_context()
@@ -656,13 +643,7 @@ def truncate(self, filepath, length, fh=None):
656643

657644
entry_id = opened_file.entry_id
658645
cache = EntryCache.get_instance().cache
659-
660-
try:
661-
entry = cache.get(entry_id)
662-
except:
663-
_logger.exception("Could not fetch normalized entry with ID "
664-
"[%s] for truncate with FH.", entry_id)
665-
raise
646+
entry = cache.get(entry_id)
666647

667648
opened_file.truncate(length)
668649
else:
@@ -724,7 +705,7 @@ def unlink(self, file_path):
724705

725706
try:
726707
gd.remove_entry(normalized_entry)
727-
except (NameError):
708+
except NameError:
728709
raise FuseOSError(ENOENT)
729710
except:
730711
_logger.exception("Could not remove file [%s] with ID [%s].",
@@ -733,13 +714,7 @@ def unlink(self, file_path):
733714
raise FuseOSError(EIO)
734715

735716
# Remove from cache. Will no longer be able to be found, locally.
736-
737-
try:
738-
PathRelations.get_instance().remove_entry_all(entry_id)
739-
except:
740-
_logger.exception("There was a problem removing entry [%s] "
741-
"from the caches.", normalized_entry)
742-
raise
717+
PathRelations.get_instance().remove_entry_all(entry_id)
743718

744719
# Remove from among opened-files.
745720

@@ -859,15 +834,11 @@ def mount(auth_storage_filepath, mountpoint, debug=None, nothreads=None,
859834

860835
try:
861836
Conf.set(k, v)
862-
except (KeyError) as e:
837+
except KeyError as e:
863838
_logger.debug("Forwarding option [%s] with value [%s] to "
864839
"FUSE.", k, v)
865840

866841
fuse_opts[k] = v
867-
except:
868-
_logger.exception("Could not set option [%s]. It is probably "
869-
"invalid.", k)
870-
raise
871842

872843
if gdrivefs.config.IS_DEBUG is True:
873844
_logger.debug("FUSE options:\n%s", pprint.pformat(fuse_opts))

gdrivefs/gdtool/drive.py

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,11 @@ def get_children_under_parent_id(self,
272272

273273
client = self.__auth.get_client()
274274

275-
if query_contains_string and query_is_string:
276-
_logger.exception("The query_contains_string and query_is_string "
277-
"parameters are mutually exclusive.")
278-
raise
275+
assert \
276+
(query_contains_string is not None and
277+
query_is_string is not None) is False,
278+
"The query_contains_string and query_is_string parameters are "\
279+
"mutually exclusive."
279280

280281
if query_is_string:
281282
query = ("title='%s'" %
@@ -302,14 +303,7 @@ def get_children_under_parent_id(self,
302303
def get_entries(self, entry_ids):
303304
retrieved = { }
304305
for entry_id in entry_ids:
305-
try:
306-
entry = self.get_entry(entry_id)
307-
except:
308-
_logger.exception("Could not retrieve entry with ID [%s].",
309-
entry_id)
310-
raise
311-
312-
retrieved[entry_id] = entry
306+
retrieved[entry_id] = self.get_entry(entry_id)
313307

314308
_logger.debug("(%d) entries were retrieved.", len(retrieved))
315309

@@ -381,15 +375,10 @@ def list_files(self, query_contains_string=None, query_is_string=None,
381375
"(%d).", len(result[u'items']), page_num)
382376

383377
for entry_raw in result[u'items']:
384-
try:
385-
entry = \
386-
gdrivefs.gdtool.normal_entry.NormalEntry(
387-
'list_files',
388-
entry_raw)
389-
except:
390-
_logger.exception("Could not normalize raw-data for entry "
391-
"with ID [%s].", entry_raw[u'id'])
392-
raise
378+
entry = \
379+
gdrivefs.gdtool.normal_entry.NormalEntry(
380+
'list_files',
381+
entry_raw)
393382

394383
entries.append(entry)
395384

@@ -434,13 +423,7 @@ def download_to_local(self, output_file_path, normalized_entry, mime_type,
434423
use_cache = False
435424
if allow_cache and os.path.isfile(output_file_path):
436425
# Determine if a local copy already exists that we can use.
437-
try:
438-
stat_info = os.stat(output_file_path)
439-
except:
440-
_logger.exception("Could not retrieve stat() information "
441-
"for temp download file [%s].",
442-
output_file_path)
443-
raise
426+
stat_info = os.stat(output_file_path)
444427

445428
if gd_mtime_epoch == stat_info.st_mtime:
446429
use_cache = True
@@ -777,7 +760,7 @@ def remove_entry(self, normalized_entry):
777760

778761
try:
779762
result = client.files().delete(**args).execute()
780-
except (Exception) as e:
763+
except Exception as e:
781764
if e.__class__.__name__ == 'HttpError' and \
782765
str(e).find('File not found') != -1:
783766
raise NameError(normalized_entry.id)

gdrivefs/gdtool/normal_entry.py

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,38 @@ def __init__(self, gd_resource_type, raw_data):
4848
# can get a file-size up-front, or we have to decide on a specific
4949
# mime-type in order to do so.
5050

51-
try:
52-
requires_mimetype = u'fileSize' not in self.__raw_data and \
53-
raw_data[u'mimeType'] != self.__directory_mimetype
51+
requires_mimetype = u'fileSize' not in self.__raw_data and \
52+
raw_data[u'mimeType'] != self.__directory_mimetype
5453

55-
self.__info['requires_mimetype'] = \
56-
requires_mimetype
57-
58-
self.__info['title'] = \
59-
raw_data[u'title']
60-
61-
self.__info['mime_type'] = \
62-
raw_data[u'mimeType']
63-
64-
self.__info['labels'] = \
65-
raw_data[u'labels']
66-
67-
self.__info['id'] = \
68-
raw_data[u'id']
69-
70-
self.__info['last_modifying_user_name'] = \
71-
raw_data[u'lastModifyingUserName']
72-
73-
self.__info['writers_can_share'] = \
74-
raw_data[u'writersCanShare']
54+
self.__info['requires_mimetype'] = \
55+
requires_mimetype
56+
57+
self.__info['title'] = \
58+
raw_data[u'title']
59+
60+
self.__info['mime_type'] = \
61+
raw_data[u'mimeType']
62+
63+
self.__info['labels'] = \
64+
raw_data[u'labels']
65+
66+
self.__info['id'] = \
67+
raw_data[u'id']
68+
69+
self.__info['last_modifying_user_name'] = \
70+
raw_data[u'lastModifyingUserName']
71+
72+
self.__info['writers_can_share'] = \
73+
raw_data[u'writersCanShare']
7574

76-
self.__info['owner_names'] = \
77-
raw_data[u'ownerNames']
78-
79-
self.__info['editable'] = \
80-
raw_data[u'editable']
81-
82-
self.__info['user_permission'] = \
83-
raw_data[u'userPermission']
84-
except KeyError:
85-
_logger.exception("Could not normalize with missing key.\nRAW:\n"
86-
"%s", pprint.pformat(raw_data))
87-
raise
75+
self.__info['owner_names'] = \
76+
raw_data[u'ownerNames']
77+
78+
self.__info['editable'] = \
79+
raw_data[u'editable']
80+
81+
self.__info['user_permission'] = \
82+
raw_data[u'userPermission']
8883

8984
self.__info['link'] = \
9085
raw_data.get(u'embedLink')

0 commit comments

Comments
 (0)