Exemplo n.º 1
0
 def fix_file_permissions(self, operation, path, path_src=None):
     apppath = path
     if apppath.endswith(utils.path_sep):
         apppath = apppath[0:len(apppath) - 1]
     apppath_src = path_src
     if apppath_src is not None:
         if apppath_src.endswith(utils.path_sep):
             apppath_src = apppath_src[0:len(apppath_src) - 1]
     else:
         apppath_src = utils.path_dirname(path)
     stat_info = utils.path_stat(apppath_src)
     mode = stat.S_IMODE(stat_info.st_mode)
     if operation == "CREATE_DIRECTORY":
         utils.path_change_permissions(path, mode)
         utils.path_change_owner(path, stat_info.st_uid, stat_info.st_gid)
     elif operation == "CREATE_FILE":
         utils.path_change_permissions(
             path, ((mode & ~stat.S_IXUSR) & ~stat.S_IXGRP) & ~stat.S_IXOTH)
         utils.path_change_owner(path, stat_info.st_uid, stat_info.st_gid)
     elif operation == "COPY_DIRECTORY" or operation == "COPY_FILE":
         utils.path_change_permissions(path, mode)
         stat_info = utils.path_stat(utils.path_dirname(
             path))  #PRENDE IL GRUPPO E L'UTENTE DELLA CARTELLA PADRE
         utils.path_change_owner(path, stat_info.st_uid, stat_info.st_gid)
     elif operation == "MOVE_DIRECTORY" or operation == "MOVE_FILE":
         utils.path_change_permissions(path, mode)
         utils.path_change_owner(path, stat_info.st_uid, stat_info.st_gid)
Exemplo n.º 2
0
    def _write(self, path, prop):
        if "encoding" in prop:
            enc = prop["encoding"]
        else:
            enc = sys.getfilesystemencoding()
        if "endline" in prop:
            endl = prop["endline"]
        else:
            endl = utils.line_sep
        bm = None

        #CREA FILE TEMPORANEO
        pathtmp = None
        sprnpath = utils.path_dirname(path)
        while True:
            r = "".join([random.choice("0123456789") for x in xrange(6)])
            pathtmp = sprnpath + utils.path_sep + "temporary" + r + ".dwstext"
            if not utils.path_exists(pathtmp):
                utils.file_open(
                    pathtmp,
                    'wb').close()  #Crea il file per imposta i permessi
                self._agent_main.get_osmodule().fix_file_permissions(
                    "CREATE_FILE", pathtmp)
                if (enc is not None):
                    flgop = "w"
                    if "bom" in prop and prop["bom"] == 'true':
                        bm = self._get_bom_byname(enc)
                        if bm is not None:
                            #Scrive BOM
                            text_file = utils.file_open(pathtmp, 'wb')
                            text_file.write(bm["Data"])
                            text_file.close()
                            flgop = "a"
                    text_file = utils.file_open(pathtmp, flgop, enc)
                else:
                    text_file = utils.file_open(pathtmp, 'w')
                break
        try:
            s = prop["text"]
            s = endl.join(s.split("\n"))
            text_file.write(s)
        finally:
            text_file.close()
        if utils.path_exists(path):
            if utils.path_isdir(path):
                utils.path_remove(self._tmpname)
                raise Exception("PATH is directory.")
            else:
                self._agent_main.get_osmodule().fix_file_permissions(
                    "COPY_FILE", pathtmp, path)
                utils.path_remove(path)
        shutil.move(pathtmp, path)