Commit 07818995 authored by Philip ABBET's avatar Philip ABBET

Force 4-spaces indentation

parent de1bbd93
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -38,82 +38,82 @@ import os
def _sha256(s):
"""A python2/3 replacement for :py:func:`haslib.sha256`"""
"""A python2/3 replacement for :py:func:`haslib.sha256`"""
try:
if isinstance(s, str): s = six.u(s)
return hashlib.sha256(s.encode('utf8')).hexdigest()
except:
return hashlib.sha256(s).hexdigest()
try:
if isinstance(s, str): s = six.u(s)
return hashlib.sha256(s.encode('utf8')).hexdigest()
except:
return hashlib.sha256(s).hexdigest()
def _stringify(dictionary):
names = sorted(dictionary.keys())
names = sorted(dictionary.keys())
converted_dictionary = '{'
for name in names:
converted_dictionary += '"%s":%s,' % (name, str(dictionary[name]))
converted_dictionary = '{'
for name in names:
converted_dictionary += '"%s":%s,' % (name, str(dictionary[name]))
if len(converted_dictionary) > 1:
converted_dictionary = converted_dictionary[:-1]
if len(converted_dictionary) > 1:
converted_dictionary = converted_dictionary[:-1]
converted_dictionary += '}'
converted_dictionary += '}'
return converted_dictionary
return converted_dictionary
def toUserPath(username):
hash = _sha256(username)
return os.path.join(hash[0:2], hash[2:4], username)
hash = _sha256(username)
return os.path.join(hash[0:2], hash[2:4], username)
def hash(dictionary_or_string):
if isinstance(dictionary_or_string, dict):
return _sha256(_stringify(dictionary_or_string))
else:
return _sha256(dictionary_or_string)
if isinstance(dictionary_or_string, dict):
return _sha256(_stringify(dictionary_or_string))
else:
return _sha256(dictionary_or_string)
def hashJSON(contents, description):
"""Hashes the pre-loaded JSON object using :py:func:`hashlib.sha256`
"""Hashes the pre-loaded JSON object using :py:func:`hashlib.sha256`
Excludes description changes
"""
Excludes description changes
"""
if description in contents:
contents = copy.deepcopy(contents) #temporary copy
del contents[description]
contents = simplejson.dumps(contents, sort_keys=True)
return hashlib.sha256(contents).hexdigest()
if description in contents:
contents = copy.deepcopy(contents) #temporary copy
del contents[description]
contents = simplejson.dumps(contents, sort_keys=True)
return hashlib.sha256(contents).hexdigest()
def hashJSONFile(path, description):
"""Hashes the JSON file contents using :py:func:`hashlib.sha256`
"""Hashes the JSON file contents using :py:func:`hashlib.sha256`
Excludes description changes
"""
Excludes description changes
"""
try:
with open(path, 'rb') as f:
return hashJSON(simplejson.load(f,
object_pairs_hook=collections.OrderedDict), description) #preserve order
except simplejson.JSONDecodeError:
# falls back to normal file content hashing
return hashFileContents(path)
try:
with open(path, 'rb') as f:
return hashJSON(simplejson.load(f,
object_pairs_hook=collections.OrderedDict), description) #preserve order
except simplejson.JSONDecodeError:
# falls back to normal file content hashing
return hashFileContents(path)
def hashFileContents(path):
"""Hashes the file contents using :py:func:`hashlib.sha256`."""
"""Hashes the file contents using :py:func:`hashlib.sha256`."""
with open(path, 'rb') as f:
sha256 = hashlib.sha256()
for chunk in iter(lambda: f.read(sha256.block_size * 1000), b''):
sha256.update(chunk)
with open(path, 'rb') as f:
sha256 = hashlib.sha256()
for chunk in iter(lambda: f.read(sha256.block_size * 1000), b''):
sha256.update(chunk)
return sha256.hexdigest()
return sha256.hexdigest()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -27,5 +27,3 @@
# #
###############################################################################
# Laurent El Shafey <Laurent.El-Shafey@idiap.ch>
# Tue 16 Jun 18:16:07 CEST 2015
......@@ -35,37 +35,37 @@ import simplejson
def main():
# resolve package name
name = 'environment'
if len(sys.argv) > 1:
name = sys.argv[1]
# resolve package name
name = 'environment'
if len(sys.argv) > 1:
name = sys.argv[1]
# resolve version
version = '1'
if len(sys.argv) > 2:
version = sys.argv[2]
# resolve version
version = '1'
if len(sys.argv) > 2:
version = sys.argv[2]
# use a configuration file if one exists
databases = None
capabilities = None
if os.path.exists('/etc/beat/environment.json'):
with open('/etc/beat/environment.json', 'r') as config_file:
config = simplejson.load(config_file)
name = config.get('name', name)
version = config.get('version', version)
databases = config.get('databases', None)
capabilities = config.get('capabilities', None)
# use a configuration file if one exists
databases = None
capabilities = None
if os.path.exists('/etc/beat/environment.json'):
with open('/etc/beat/environment.json', 'r') as config_file:
config = simplejson.load(config_file)
name = config.get('name', name)
version = config.get('version', version)
databases = config.get('databases', None)
capabilities = config.get('capabilities', None)
# print the result
retval = collections.OrderedDict()
retval['name'] = name
retval['version'] = version
retval['os'] = platform.uname()
# print the result
retval = collections.OrderedDict()
retval['name'] = name
retval['version'] = version
retval['os'] = platform.uname()
if databases is not None:
retval['databases'] = databases
if databases is not None:
retval['databases'] = databases
if capabilities is not None:
retval['capabilities'] = capabilities
if capabilities is not None:
retval['capabilities'] = capabilities
print(simplejson.dumps(retval, indent=2))
print(simplejson.dumps(retval, indent=2))
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment