MCPcopy
hub / github.com/aws/aws-cli / create_file

Method create_file

awscli/testutils.py:608–636  ·  view source on GitHub ↗

Creates a file in a tmpdir ``filename`` should be a relative path, e.g. "foo/bar/baz.txt" It will be translated into a full path in a tmp dir. If the ``mtime`` argument is provided, then the file's mtime will be set to the provided value (must be an epoch time).

(
        self, filename, contents, mtime=None, mode='w', encoding=None
    )

Source from the content-addressed store, hash-verified

606 shutil.rmtree(self.rootdir)
607
608 def create_file(
609 self, filename, contents, mtime=None, mode='w', encoding=None
610 ):
611 """Creates a file in a tmpdir
612
613 ``filename`` should be a relative path, e.g. "foo/bar/baz.txt"
614 It will be translated into a full path in a tmp dir.
615
616 If the ``mtime`` argument is provided, then the file's
617 mtime will be set to the provided value (must be an epoch time).
618 Otherwise the mtime is left untouched.
619
620 ``mode`` is the mode the file should be opened either as ``w`` or
621 `wb``.
622
623 Returns the full path to the file.
624
625 """
626 full_path = os.path.join(self.rootdir, filename)
627 if not os.path.isdir(os.path.dirname(full_path)):
628 os.makedirs(os.path.dirname(full_path))
629 with open(full_path, mode, encoding=encoding) as f:
630 f.write(contents)
631 current_time = os.path.getmtime(full_path)
632 # Subtract a few years off the last modification date.
633 os.utime(full_path, (current_time, current_time - 100000000))
634 if mtime is not None:
635 os.utime(full_path, (mtime, mtime))
636 return full_path
637
638 def create_file_with_size(self, filename, filesize):
639 filename = self.create_file(filename, contents='')

Callers 1

create_file_with_sizeMethod · 0.95

Calls 3

isdirMethod · 0.45
makedirsMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected