创建的tar.gz在创建后在linux上传输时不具有执行权限。
目标:文件应该拥有完全的权利,一旦它是在linux系统上。
我使用python中的'tarfile‘库来实现这一点。
import os
import tarfile
with tarfile.open('test.tar.gz', "x:gz") as tar:
tar.add("path_to_src_folder", arcname=os.path.basename("path_to_dir", filter=tarinfo.mode(777))
正如标题所述,我有几个文件夹,几个.ppm.bz2文件,我想要提取它们使用python的确切位置。
我在文件夹中遍历如下:
import tarfile
import os
path = '/Users/ankitkumar/Downloads/colorferet/dvd1/data/images/'
folders = os.listdir(path)
for folder in folders: #the folders starting like 00001
if not folder.startswith("0"):
我有一堆文件,对这些文件进行以下处理:
for file_name in filelist:
tar_file = tarfile.open(file_name)
tar_file.extractall("./" + "location")
对于特定的文件,在tarfile.open调用之后立即收到此错误:
$ file file_name.tgz
file_name.tgz: gzip compressed data, from Unix, last modified: Mon Dec 16 16:33:34 2013
回溯(最近一次调用):
F
我正在尝试写一个python程序,它最终将接受文件的命令行参数,确定它是tar还是zip等文件,然后相应地提取它。我现在只是试图让tar部分正常工作,但我收到了多个错误。我要检查的文件位于我的~/目录中。任何想法都是很棒的。
#!/usr/bin/python
import tarfile
import os
def open_tar(file):
if tarfile.is_tarfile(file):
try:
tar = tarfile.open("file")
tar.extractall()
我正在尝试从这个网站下载tgz文件:
这是我的剧本:
import os
from six.moves import urllib
import tarfile
spam_path=os.path.join('ML', 'spam')
root_download='https://plg.uwaterloo.ca/cgi-bin/cgiwrap/gvcormac/foo07'
spam_url=root_download+'255 MB Corpus (trec07p.tgz)'
if not os.path.isdir(sp
我正在尝试编写一个函数,将包含不同权限的文件的目录备份到Windows XP上的存档中。我使用tarfile模块来压缩目录。目前,只要程序遇到没有读取权限的文件,它就会停止给出错误: IOError: Errno 13权限被拒绝:‘文件路径’。我希望它只跳过它无法读取的文件,而不是结束tar操作。这是我现在使用的代码:
def compressTar():
"""Build and gzip the tar archive."""
folder = 'C:\\Documents and Settings'
tar = tar
我得到以下错误...
Traceback (most recent call last):
File "deploycommerce.py", line 56, in <module>
if tarfile.is_tarfile(optfile):
File "/usr/lib/python2.7/tarfile.py", line 2587, in is_tarfile
t = open(name)
File "/usr/lib/python2.7/tarfile.py", line 1658, in o
我使用的是Python 2.7。我有一个使用python tarfile库解压缩到/opt中的.tar.gz文件。但是,当我尝试使用以下命令解压它时:
tar -xPzvf myfile.tar.gz
我得到以下错误:
tar: /: Cannot utime: Operation not permitted
tar: Exiting with failure status due to previous errors
看起来tar文件正在尝试直接修改上次修改时间?我查看了tarfile提供的选项,但除了实际的修改时间之外,找不到任何相关的内容。
我需要提取一些使用python压缩成.xz文件的文本文件。
我的代码只是
import tarfile
tarfile.open('file.xz')
但此操作失败,并显示以下错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/tarfile.py", line 1558, in open
raise ReadError("file could not
我想知道如何仅使用Python代码将tar文件转换为tar.gz?我试过很多问题,但都没有用。
我得到了不同的错误:
使用gzip.open,他创建了一个包含"tar“的"gz”文件。
import gzip
tarfile = "/home/user/file.tar"
with open(tarfile, 'rb') as f_in:
with gzip.open(tarfile+'.gz', 'wb') as f_out:
f_out.writelines(f_i
我让mod_wsgi在RHEL/Apache2.4/python3.4/Django1.11/virtualenv.上工作得很好然后,我使用虚拟环境中的pip将numpy从1.14.0升级到1.14.2,安装熊猫,并安装其他模块。然后我重新启动Apache,并开始获取指示AttributeError: 'module' object has no attribute 'arange' when trying to call numpy.arange的服务器错误,或者在尝试调用matplotlib.use('Agg')时出现类似的错误等等。
我用下
我尝试在我的python文件中运行命令,该文件位于动态文件中。我尝试使用import语句,据我所知,对于这种情况,这是更好的解决方案。
代码如下:
from subprocess import call
import tarfile
from contextlib import closing
def tarfile1(path):
with closing(tarfile.open(path)) as tar:
tar.extractall(path)
import path as runcommand
runcommand.main()
问题是path
Ansible unbale to run python script from playbook如果我尝试手动运行python脚本,它工作得很好。但是,当我执行Playbook中的脚本时,它无法识别变量。我得到了以下错误: TASK [Updates the current location for the test] *****************************************************************************************************************************************
问题是I used ps aux | grep apache,它说apache是以无名小卒的身份运行的。但后来我使用了exec("whoami"),它给出了一个不同的结果:根或gt。这取决于脚本的所有者。如果脚本归root所有,root就是gt;如果脚本归gt所有,那么whoami就是gt。我还检查了httpd.conf,apache的用户是无名小卒,组是无名小卒。
有人能解释一下这件事吗?
谢谢!
我正在尝试向python中的gzipped tarfile中添加一个文件。
import tarfile
# create test file
with open("testfile.txt", "w") as f:
f.write("TESTTESTTEST")
# create archive
with tarfile.open("archfile.tar.gz", "x:gz") as archive:
with open("testfile.txt", 'rb