Skip to content

Instantly share code, notes, and snippets.

@dicato
Created August 15, 2012 19:51
Show Gist options
  • Save dicato/3363062 to your computer and use it in GitHub Desktop.
Save dicato/3363062 to your computer and use it in GitHub Desktop.
@staticmethod
def local_file_uri(file_path):
'''
Helper/Utility method to take file system paths and return a file URI for use
with learn, and learn_policy methods
Args:
file_path: The file path to the policy
Returns:
an equivalent file URI
'''
if os.path.isfile(file_path):
try:
with open(file_path):
pass
except IOError:
raise IOError('Cannot open and read rules file, %s' % file_path)
else:
raise IOError('Cannot find rules file, %s' % file_path)
full_path = urllib.pathname2url(os.path.abspath(file_path))
if file_path.startswith("file://"):
return full_path
else:
return "file://" + full_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment