Created
August 15, 2012 19:51
-
-
Save dicato/3363062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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