コード例 #1
0
 def backup(self, backupToken):
     """
         Puts a backup of this config to the location specified in @backupPath.
     """
     pdosq.makedirs(settings.UCI_BACKUP_DIR)
     backupPath = "{}/{}-{}".format(settings.UCI_BACKUP_DIR, self.myname,
             backupToken)
     pdos.copy(self.filepath, backupPath)
コード例 #2
0
ファイル: uci.py プロジェクト: SejalChauhan/Paradrop
    def restore(self, backupToken, saveBackup=True):
        """
            Replaces real file (at /etc/config/*) with backup copy from /tmp/*-@backupToken location.

            Arguments:
                backupToken: The backup token appended at the end of the backup path
                saveBackup : A flag to keep a backup copy or delete it (default is keep backup)
        """
        # Make sure it exists!
        backupPath = '/tmp/%s-%s' % (self.myname, backupToken)
        if(pdos.exists(backupPath)):
            if(saveBackup):
                pdos.copy(backupPath, self.filepath)
            else:
                pdos.move(backupPath, self.filepath)
        else:
            # This might be ok if they didn't actually make any changes
            out.warn('Cannot restore, %s missing backup (might be OK if no changes made)\n' % (self.myname))
コード例 #3
0
    def restore(self, backupToken, saveBackup=True):
        """
            Replaces real file (at /etc/config/*) with backup copy from /tmp/*-@backupToken location.

            Arguments:
                backupToken: The backup token appended at the end of the backup path
                saveBackup : A flag to keep a backup copy or delete it (default is keep backup)
        """
        # Make sure it exists!
        backupPath = "{}/{}-{}".format(settings.UCI_BACKUP_DIR, self.myname,
                backupToken)
        if(pdos.exists(backupPath)):
            if(saveBackup):
                pdos.copy(backupPath, self.filepath)
            else:
                pdos.move(backupPath, self.filepath)
        else:
            # This might be ok if they didn't actually make any changes
            out.warn('Cannot restore, %s missing backup (might be OK if no changes made)\n' % (self.myname))
コード例 #4
0
ファイル: test_utils.py プロジェクト: SejalChauhan/Paradrop
def test_pdos():
    """
    Test pdos utility module
    """
    assert pdos.getMountCmd() == "mount"
    assert pdos.isMount("/")
    assert pdos.ismount("/")

    assert pdos.oscall("true") is None
    assert pdos.oscall("false") is not None
    assert pdos.oscall("echo hello") is None
    assert pdos.oscall("echo hello 1>&2") is None

    assert pdos.syncFS() is None

    # Make a file, check that our functions respond correctly to it
    path = writeTempFile("hello")
    assert pdos.fixpath(path) == path
    assert "text" in pdos.getFileType(path)
    assert pdos.exists(path)
    assert not pdos.isdir(path)
    assert pdos.isfile(path)

    # Remove the file, check that our functions detect that
    pdos.unlink(path)
    assert pdos.fixpath(path) == path
    assert pdos.getFileType(path) is None
    assert not pdos.exists(path)
    assert not pdos.isdir(path)
    assert not pdos.isfile(path)

    # Make a directory there instead
    pdos.mkdir(path)
    assert pdos.fixpath(path) == path
    assert "directory" in pdos.getFileType(path)
    assert pdos.exists(path)
    assert pdos.isdir(path)
    assert not pdos.isfile(path)

    # Now we will do some manipulations on files under that directory
    a = os.path.join(path, "a")
    b = os.path.join(path, "b")
    c = os.path.join(path, "c")
    d = os.path.join(path, "d")

    pdos.write(a, "hello")
    assert pdos.isfile(a)
    pdos.copy(a, b)
    assert pdos.isfile(b)
    pdos.symlink(a, c)
    assert pdos.isfile(c)
    pdos.move(a, b)
    assert not pdos.isfile(a)
    pdos.remove(b)
    assert not pdos.isfile(b)
    pdos.mkdir(a)
    pdos.copytree(a, b)
    assert pdos.isdir(b)

    # Remove a non-empty directory
    pdos.remove(path)
    assert not pdos.isdir(path)

    # This file is under a directory that no longer exists, so the write must
    # fail.
    #
    # TODO: These should not fail silently.  They should either return an error
    # indicator or raise an exception.
    pdos.writeFile(a, "c")
    pdos.write(a, "c")

    # Test various ways to call writeFile
    pdos.writeFile(path, ["a", "b"])
    pdos.writeFile(path, "c")
    pdos.writeFile(path, 5)  # This one does nothing.

    # Test the content with readFile
    data = pdos.readFile(path, array=False, delimiter="")
    assert data == "abc"
    data = pdos.readFile(path, array=True)
    assert data == ["a", "b", "c"]
    pdos.remove(path)
    assert pdos.readFile(path) is None
コード例 #5
0
def test_pdos():
    """
    Test pdos utility module
    """
    assert pdos.getMountCmd() == "mount"
    assert pdos.isMount("/")
    assert pdos.ismount("/")

    assert pdos.oscall("true") is None
    assert pdos.oscall("false") is not None
    assert pdos.oscall("echo hello") is None
    assert pdos.oscall("echo hello 1>&2") is None

    # Make a file, check that our functions respond correctly to it
    path = writeTempFile("hello")
    assert pdos.fixpath(path) == path
    assert "text" in pdos.getFileType(path)
    assert pdos.exists(path)
    assert not pdos.isdir(path)
    assert pdos.isfile(path)

    # Remove the file, check that our functions detect that
    pdos.unlink(path)
    assert pdos.fixpath(path) == path
    assert pdos.getFileType(path) is None
    assert not pdos.exists(path)
    assert not pdos.isdir(path)
    assert not pdos.isfile(path)

    # Make a directory there instead
    pdos.mkdir(path)
    assert pdos.fixpath(path) == path
    assert "directory" in pdos.getFileType(path)
    assert pdos.exists(path)
    assert pdos.isdir(path)
    assert not pdos.isfile(path)

    # Now we will do some manipulations on files under that directory
    a = os.path.join(path, "a")
    b = os.path.join(path, "b")
    c = os.path.join(path, "c")
    d = os.path.join(path, "d")

    pdos.write(a, "hello")
    assert pdos.isfile(a)
    pdos.copy(a, b)
    assert pdos.isfile(b)
    pdos.symlink(a, c)
    assert pdos.isfile(c)
    pdos.move(a, b)
    assert not pdos.isfile(a)
    pdos.remove(b)
    assert not pdos.isfile(b)
    pdos.mkdir(a)
    pdos.copytree(a, b)
    assert pdos.isdir(b)

    # Remove a non-empty directory
    pdos.remove(path)
    assert not pdos.isdir(path)

    # This file is under a directory that no longer exists, so the write must
    # fail.
    #
    # TODO: These should not fail silently.  They should either return an error
    # indicator or raise an exception.
    pdos.writeFile(a, "c")
    pdos.write(a, "c")

    # Test various ways to call writeFile
    pdos.writeFile(path, ["a", "b"])
    pdos.writeFile(path, "c")
    pdos.writeFile(path, 5)  # This one does nothing.

    # Test the content with readFile
    data = pdos.readFile(path, array=False, delimiter="")
    assert data == "abc"
    data = pdos.readFile(path, array=True)
    assert data == ["a", "b", "c"]
    pdos.remove(path)
    assert pdos.readFile(path) is None
コード例 #6
0
ファイル: uci.py プロジェクト: SejalChauhan/Paradrop
 def backup(self, backupToken):
     """
         Puts a backup of this config to the location specified in @backupPath.
     """
     backupPath = '/tmp/%s-%s' % (self.myname, backupToken)
     pdos.copy(self.filepath, backupPath)