Skip to content

Commit

Permalink
WIP hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Jun 24, 2015
1 parent 1398d11 commit 3f19916
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions vistrails/core/modules/basic_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
pipelines."""
from __future__ import division

import vistrails.core.cache.hasher
from vistrails.core.cache.hasher import Hasher
from vistrails.core.debug import format_exception
from vistrails.core.modules.module_registry import get_module_registry
from vistrails.core.modules.vistrails_module import Module, new_module, \
Expand Down Expand Up @@ -435,6 +435,7 @@ def compute(self):
Path.default_value = PathObject('')

def path_parameter_hasher(p):
# Here 'p' is a constant parameter, therefore relative_to is 'absolute'
def get_mtime(path):
t = int(os.path.getmtime(path))
if os.path.isdir(path):
Expand All @@ -444,7 +445,7 @@ def get_mtime(path):
t = max(t, get_mtime(subpath))
return t

h = vistrails.core.cache.hasher.Hasher.parameter_signature(p)
h = Hasher.parameter_signature(p)
try:
# FIXME: This will break with aliases - I don't really care that much
t = get_mtime(p.strValue)
Expand All @@ -455,11 +456,37 @@ def get_mtime(path):
hasher.update(str(t))
return hasher.digest()

def path_module_hasher(pipeline, module, constant_hasher_map):
# If 'value' is set, just hash normally (it's an absolute path)
# If not, look at relative_to: if it's 'absolute' or not set, hash normally
# If it's one of the other values, hash the relevant info. If it's an input
# connection, hash everything just in case, and emit a warning
if ('value' in module.connected_input_ports or
any(f.name == 'value' for f in module.functions)):
return Hasher.module_signature(module, constant_hasher_map)
else:
rel_to = None
for function in module.functions:
if function.name == 'relative_to':
rel_to = function.parameters[0].strValue
break
hasher = sha_hash()
hasher.update(Hasher.module_signature(module,
constant_hasher_map))
if rel_to == 'vtfile':
pass # TODO: where do I get this from, at the hasher level!?
elif rel_to == 'cwd':
hasher.update(os.getcwd())
elif rel_to == 'vistrails':
hasher.update(vistrails.core.system.vistrails_root_directory())
return hasher.digest()

class File(Path):
"""File is a VisTrails Module that represents a file stored on a
file system local to the machine where VisTrails is running."""

_settings = ModuleSettings(constant_signature=path_parameter_hasher,
signature=path_module_hasher,
constant_widget=("%s:FileChooserWidget" %
constant_config_path))
_input_ports = [IPort("value", "File"),
Expand All @@ -479,6 +506,7 @@ def compute(self):
class Directory(Path):

_settings = ModuleSettings(constant_signature=path_parameter_hasher,
signature=path_module_hasher,
constant_widget=("%s:DirectoryChooserWidget" %
constant_config_path))
_input_ports = [IPort("value", "Directory"),
Expand Down

0 comments on commit 3f19916

Please sign in to comment.