(self)
return self.ok()
perform planned actions
perform planned actions
perform planned actions
def apply(self):
        """ perform planned actions """

        if self.should('rmdir'):
            self.do('rmdir')
            Path(self.name).rmdir()
            return self.ok()

        if self.should('mkdir'):
            self.do('mkdir')
            if self.mode:
                os.makedirs(self.name, self.mode)
            else:
                os.makedirs(self.name)

        # TODO: move the guts of these into something like a FileUtils class
        if self.should('chmod'):
            self.do('chmod')
            os.chmod(self.name, self.mode)

        if self.should('chown'):
            self.do('chown')
            try:
                shutil.chown(self.name, user=self.owner)
            except PermissionError:
                return self.fatal("chown failed")

        if self.should('chgrp'):
            self.do('chgrp')
            try:
                shutil.chown(self.name, group=self.group)
            except PermissionError:
                return self.fatal("chgrp failed")

        return self.ok()
def apply ( self ) : if self . should ( 'rmdir' ) : self . do ( 'rmdir' ) Path ( self . name ) . rmdir ( ) return self . ok ( ) if self . should ( 'mkdir' ) : self . do ( 'mkdir' ) if self . mode : os . makedirs ( self . name , self . mode ) else : os . makedirs ( self . name ) # TODO: move the guts of these into something like a FileUtils class if self . should ( 'chmod' ) : self . do ( 'chmod' ) os . chmod ( self . name , self . mode ) if self . should ( 'chown' ) : self . do ( 'chown' ) try : shutil . chown ( self . name , user = self . owner ) except PermissionError : return self . fatal ( "chown failed" ) if self . should ( 'chgrp' ) : self . do ( 'chgrp' ) try : shutil . chown ( self . name , group = self . group ) except PermissionError : return self . fatal ( "chgrp failed" ) return self . ok ( )