Skip to content

Commit

Permalink
Merge pull request #192 from google/tidy
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
jaqx0r authored May 28, 2023
2 parents 0981059 + f4ed298 commit ba56c14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
36 changes: 18 additions & 18 deletions nss_cache/update/map_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def UpdateCacheFromSource(
Returns:
An int indicating the success of an update (0 == good, fail otherwise).
"""
return_val = 0
error_count = 0
incremental = incremental and self.can_do_incremental

timestamp = self.GetModifyTimestamp()
Expand All @@ -62,7 +62,7 @@ def UpdateCacheFromSource(
self.map_name, since=timestamp, location=location
)
try:
return_val += self._IncrementalUpdateFromMap(cache, source_map)
error_count += self._IncrementalUpdateFromMap(cache, source_map)
except (error.CacheNotFound, error.EmptyMap):
self.log.warning("Local cache is invalid, faulting to a full sync.")
incremental = False
Expand All @@ -71,9 +71,9 @@ def UpdateCacheFromSource(
# fail through to a full sync.
if not incremental:
source_map = source.GetMap(self.map_name, location=location)
return_val += self.FullUpdateFromMap(cache, source_map, force_write)
error_count += self.FullUpdateFromMap(cache, source_map, force_write)

return return_val
return error_count

def _IncrementalUpdateFromMap(self, cache, new_map):
"""Merge a given map into the provided cache.
Expand All @@ -88,7 +88,7 @@ def _IncrementalUpdateFromMap(self, cache, new_map):
Raises:
EmptyMap: We're trying to merge into cache with an emtpy map.
"""
return_val = 0
error_count = 0

if len(new_map) == 0:
self.log.info("Empty map on incremental update, skipping")
Expand All @@ -101,19 +101,19 @@ def _IncrementalUpdateFromMap(self, cache, new_map):
raise error.EmptyMap

if cache_map.Merge(new_map):
return_val += cache.WriteMap(map_data=cache_map)
if return_val == 0:
error_count += cache.WriteMap(map_data=cache_map)
if error_count == 0:
self.WriteModifyTimestamp(new_map.GetModifyTimestamp())
else:
self.WriteModifyTimestamp(new_map.GetModifyTimestamp())
self.log.info("Nothing new merged, returning")

# We did an update, even if nothing was written, so write our
# update timestamp unless there is an error.
if return_val == 0:
if error_count == 0:
self.WriteUpdateTimestamp()

return return_val
return error_count

def FullUpdateFromMap(self, cache, new_map, force_write=False):
"""Write a new map into the provided cache (overwrites).
Expand All @@ -130,22 +130,22 @@ def FullUpdateFromMap(self, cache, new_map, force_write=False):
Raises:
EmptyMap: Update is an empty map, not raised if force_write=True.
"""
return_val = 0
error_count = 0

if len(new_map) == 0 and not force_write:
raise error.EmptyMap(
"Source map empty during full update, aborting. "
"Use --force-write to override."
)

return_val = cache.WriteMap(map_data=new_map, force_write=force_write)
error_count = cache.WriteMap(map_data=new_map, force_write=force_write)

# We did an update, write our timestamps unless there is an error.
if return_val == 0:
if error_count == 0:
self.WriteModifyTimestamp(new_map.GetModifyTimestamp())
self.WriteUpdateTimestamp()

return return_val
return error_count


class AutomountUpdater(updater.Updater):
Expand Down Expand Up @@ -218,7 +218,7 @@ def UpdateFromSource(self, source, incremental=True, force_write=False):
Returns:
An int indicating success of update (0 == good, fail otherwise).
"""
return_val = 0
error_count = 0

self.log.info("Retrieving automount master map.")
master_map = source.GetAutomountMasterMap()
Expand All @@ -236,7 +236,7 @@ def UpdateFromSource(self, source, incremental=True, force_write=False):
"Local master map specified but no map found! "
"No maps will update."
)
return return_val + 1
return error_count + 1

# update specific maps, e.g. auto.home and auto.auto
for map_entry in master_map:
Expand Down Expand Up @@ -269,7 +269,7 @@ def UpdateFromSource(self, source, incremental=True, force_write=False):
self.cache_options,
automount_mountpoint=automount_mountpoint,
)
return_val += update_obj.UpdateCacheFromSource(
error_count += update_obj.UpdateCacheFromSource(
cache, source, incremental, force_write, source_location
)
# with sub-maps updated, write modified master map to disk if configured to
Expand All @@ -281,6 +281,6 @@ def UpdateFromSource(self, source, incremental=True, force_write=False):
update_obj = MapUpdater(
self.map_name, self.timestamp_dir, self.cache_options
)
return_val += update_obj.FullUpdateFromMap(cache, master_map)
error_count += update_obj.FullUpdateFromMap(cache, master_map)

return return_val
return error_count
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ based_on_style = google

[pylint]

[isort]
profile = "black"

[flake8]
max-line-length = 120
extend-ignore = E203

0 comments on commit ba56c14

Please sign in to comment.