python角色权限的设置_使用python设置组权限

那是我的设置:

我有一个VirtualMachine(Ubuntu 14.04.LTS),在那里运行一个PostgreSQL / PostGIS数据库.

使用QGIS中的Windows 7,我连接到该数据库,并将功能图层加载到我的GIS项目中.

使用一些python代码,我创建一个文件与瓷砖ID和一些信息.

import os

import io

import time

layer=None

for lyr in QgsMapLayerRegistry.instance().mapLayers().values():

if lyr.name() == "fishnet_final":

layer = lyr

for f in layer.selectedFeatures():

pth = os.path.join(os.path.dirname(r'H:\path_to_file\'), str(f['name']) + "_" + str(time.strftime("%Y-%m-%d")) + "_" + str(f['country']) + ".txt")

fle = open(pth,'wb')

fle.writelines(str(f['name']))

fle.write('\n')

fle.write(str(time.strftime("%Y-%d-%m")))

fle.write('\n')

fle.write(str(f['country']))

fle.write('\n')

fle.close()

os.rename(pth, pth.replace(' ', ''))

该文件具有以下权限:

-rwx------

我想为我的组和其他设置相同的权限.

-rwxrwxrwx

我试过了:

import shlex

command=shlex.split("chmod 777 r'H:\path_to_file\file.txt'")

subprocess.call(command)

没有成功.

工作是什么

command=shlex.split("touch r'H:\path_to_file\file.txt'")

要么

command=shlex.split("rm r'H:\path_to_file\file.txt'")

为什么不使用chmod命令?

在UNIX下,我可以chmod这个文件,我和Windows中的用户一样.

我也尝试过os.chmod方法.但没有成功.

import os, stat

st = os.stat(r'H:\path_to_file\file.txt')

os.chmod(r'H:\path_to_file\file.txt', st.st_mode | 0o111 )

UPDATE

当我在UNIX(Solaris)下执行“chmod 777文件”权限时

-rwxrwxrwx

我现在可以做的是在GIS项目下降级/删除Windows下的权限:

subprocess.call(r'chmod 400 "H:\path_to_file\file.txt"', shell=True)

0

-r-xr-xr-x

使用这个命令,我得到一个0反馈在python控制台输出

当我在新文件上执行chmod 777时,我也得到一个0反馈,但没有任何反应.

问题是我只能降级权限.我无法设置新的权限!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值