示例#1
0
 def _get_file_contents(self, file_path):
     full_path = os.path.expandvars(os.path.expanduser(file_path))
     try:
         with compat_open(full_path) as f:
             return f.read()
     except (OSError, IOError, UnicodeDecodeError) as e:
         raise exceptions.FileLoadError(file_path=file_path, error=e)
示例#2
0
文件: deploy.py 项目: aws/aws-cli
 def _get_file_contents(self, file_path):
     full_path = os.path.expandvars(os.path.expanduser(file_path))
     try:
         with compat_open(full_path) as f:
             return f.read()
     except (OSError, IOError, UnicodeDecodeError) as e:
         raise exceptions.FileLoadError(
             file_path=file_path, error=e)
def get_file(prefix, path):
    file_path = path[len(prefix):]
    file_path = os.path.expanduser(file_path)
    file_path = os.path.expandvars(file_path)
    if not os.path.isfile(file_path):
        raise ResourceLoadingError("file does not exist: %s" % file_path)
    try:
        with compat_open(file_path, 'r') as f:
            return f.read()
    except (OSError, IOError) as e:
        raise ResourceLoadingError('Unable to load paramfile %s: %s' % (
            path, e))
示例#4
0
def get_file(prefix, path, mode):
    file_path = path[len(prefix):]
    file_path = os.path.expanduser(file_path)
    file_path = os.path.expandvars(file_path)
    if not os.path.isfile(file_path):
        raise ResourceLoadingError("file does not exist: %s" % file_path)
    try:
        with compat_open(file_path, mode) as f:
            return f.read()
    except (OSError, IOError) as e:
        raise ResourceLoadingError('Unable to load paramfile %s: %s' %
                                   (path, e))
示例#5
0
def get_file(prefix, path, mode):
    file_path = os.path.expandvars(os.path.expanduser(path[len(prefix):]))
    try:
        with compat_open(file_path, mode) as f:
            return f.read()
    except UnicodeDecodeError:
        raise ResourceLoadingError(
            'Unable to load paramfile (%s), text contents could '
            'not be decoded.  If this is a binary file, please use the '
            'fileb:// prefix instead of the file:// prefix.' % file_path)
    except (OSError, IOError) as e:
        raise ResourceLoadingError('Unable to load paramfile %s: %s' %
                                   (path, e))
示例#6
0
def get_file(prefix, path, mode):
    file_path = os.path.expandvars(os.path.expanduser(path[len(prefix):]))
    try:
        with compat_open(file_path, mode) as f:
            return f.read()
    except UnicodeDecodeError:
        raise ResourceLoadingError(
            'Unable to load paramfile (%s), text contents could '
            'not be decoded.  If this is a binary file, please use the '
            'fileb:// prefix instead of the file:// prefix.' % file_path)
    except (OSError, IOError) as e:
        raise ResourceLoadingError('Unable to load paramfile %s: %s' % (
            path, e))
 def test_user_data(self):
     data = u'\u0039'
     with temporary_file('r+') as tmp:
         with compat_open(tmp.name, 'w') as f:
             f.write(data)
             f.flush()
             args = (
                 self.prefix +
                 ' --image-id foo --user-data file://%s' % f.name)
             result = {'ImageId': 'foo',
                       'MaxCount': '1',
                       'MinCount': '1',
                       # base64 encoded content of utf-8 encoding of data.
                       'UserData': 'OQ=='}
         self.assert_params_for_cmd(args, result)
示例#8
0
 def test_user_data(self):
     data = u'\u0039'
     with temporary_file('r+') as tmp:
         with compat_open(tmp.name, 'w') as f:
             f.write(data)
             f.flush()
             args = (
                 self.prefix +
                 ' --image-id foo --user-data file://%s' % f.name)
             result = {'ImageId': 'foo',
                       'MaxCount': '1',
                       'MinCount': '1',
                       # base64 encoded content of utf-8 encoding of data.
                       'UserData': 'OQ=='}
         self.assert_params_for_cmd(args, result)
示例#9
0
 def test_user_data(self):
     return
     data = u"\u0039"
     with temporary_file("r+") as tmp:
         with compat_open(tmp.name, "w") as f:
             f.write(data)
             f.flush()
             args = self.prefix + " --image-id foo --user-data file://%s" % f.name
             result = {
                 "ImageId": "foo",
                 "MaxCount": 1,
                 "MinCount": 1,
                 # base64 encoded content of utf-8 encoding of data.
                 "UserData": "OQ==",
             }
         self.assert_params_for_cmd(args, result)