mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-27 02:16:12 +01:00
add binary flag to open where needed
This commit is contained in:
parent
e97c1de936
commit
776a069df9
@ -2942,7 +2942,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
|
|
||||||
# helper function to download a file from a specific revision
|
# helper function to download a file from a specific revision
|
||||||
def download(self, name, md5, dir, destfile):
|
def download(self, name, md5, dir, destfile):
|
||||||
o = open(destfile, 'w')
|
o = open(destfile, 'wb')
|
||||||
if md5 != '':
|
if md5 != '':
|
||||||
query = {'rev': dir['srcmd5']}
|
query = {'rev': dir['srcmd5']}
|
||||||
u = makeurl(dir['apiurl'], ['source', dir['project'], dir['package'], pathname2url(name)], query=query)
|
u = makeurl(dir['apiurl'], ['source', dir['project'], dir['package'], pathname2url(name)], query=query)
|
||||||
@ -3126,7 +3126,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
pac.put_on_conflictlist(name)
|
pac.put_on_conflictlist(name)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
o = open(os.path.join(destdir, name), 'w')
|
o = open(os.path.join(destdir, name), 'wb')
|
||||||
code = subprocess.call(['diff3', '-m',
|
code = subprocess.call(['diff3', '-m',
|
||||||
'-L', '.mine',
|
'-L', '.mine',
|
||||||
os.path.join(destdir, name + '.mine'),
|
os.path.join(destdir, name + '.mine'),
|
||||||
|
24
osc/core.py
24
osc/core.py
@ -1531,10 +1531,10 @@ def http_request(method, url, headers={}, data=None, file=None, timeout=100):
|
|||||||
if file and not data:
|
if file and not data:
|
||||||
size = os.path.getsize(file)
|
size = os.path.getsize(file)
|
||||||
if size < 1024*512:
|
if size < 1024*512:
|
||||||
data = open(file).read()
|
data = open(file, 'rb').read()
|
||||||
else:
|
else:
|
||||||
import mmap
|
import mmap
|
||||||
filefd = open(file, 'r')
|
filefd = open(file, 'rb')
|
||||||
try:
|
try:
|
||||||
if sys.platform[:3] != 'win':
|
if sys.platform[:3] != 'win':
|
||||||
data = mmap.mmap(filefd.fileno(), os.path.getsize(file), mmap.MAP_SHARED, mmap.PROT_READ)
|
data = mmap.mmap(filefd.fileno(), os.path.getsize(file), mmap.MAP_SHARED, mmap.PROT_READ)
|
||||||
@ -1547,7 +1547,7 @@ def http_request(method, url, headers={}, data=None, file=None, timeout=100):
|
|||||||
'\non a filesystem which does not support this.' % (e, file))
|
'\non a filesystem which does not support this.' % (e, file))
|
||||||
elif hasattr(e, 'winerror') and e.winerror == 5:
|
elif hasattr(e, 'winerror') and e.winerror == 5:
|
||||||
# falling back to the default io
|
# falling back to the default io
|
||||||
data = open(file).read()
|
data = open(file, 'rb').read()
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -2160,7 +2160,7 @@ def get_source_file(apiurl, prj, package, filename, targetfilename=None, revisio
|
|||||||
if revision:
|
if revision:
|
||||||
query = { 'rev': revision }
|
query = { 'rev': revision }
|
||||||
|
|
||||||
o = open(targetfilename or filename, 'w')
|
o = open(targetfilename or filename, 'wb')
|
||||||
u = makeurl(apiurl, ['source', prj, package, pathname2url(filename)], query=query)
|
u = makeurl(apiurl, ['source', prj, package, pathname2url(filename)], query=query)
|
||||||
for buf in streamfile(u, http_GET, BUFSIZE):
|
for buf in streamfile(u, http_GET, BUFSIZE):
|
||||||
o.write(buf)
|
o.write(buf)
|
||||||
@ -2194,7 +2194,7 @@ def get_binary_file(apiurl, prj, repo, arch,
|
|||||||
os.chmod(tmpfilename, 0644)
|
os.chmod(tmpfilename, 0644)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
o = os.fdopen(fd, 'w')
|
o = os.fdopen(fd, 'wb')
|
||||||
|
|
||||||
downloaded = 0
|
downloaded = 0
|
||||||
while 1:
|
while 1:
|
||||||
@ -2244,7 +2244,7 @@ def dgst(file):
|
|||||||
import md5
|
import md5
|
||||||
md5 = md5
|
md5 = md5
|
||||||
s = md5.md5()
|
s = md5.md5()
|
||||||
f = open(file, 'r')
|
f = open(file, 'rb')
|
||||||
while 1:
|
while 1:
|
||||||
buf = f.read(BUFSIZE)
|
buf = f.read(BUFSIZE)
|
||||||
if not buf: break
|
if not buf: break
|
||||||
@ -2262,7 +2262,7 @@ def binary(s):
|
|||||||
|
|
||||||
def binary_file(fn):
|
def binary_file(fn):
|
||||||
"""read 4096 bytes from a file named fn, and call binary() on the data"""
|
"""read 4096 bytes from a file named fn, and call binary() on the data"""
|
||||||
return binary(open(fn, 'r').read(4096))
|
return binary(open(fn, 'rb').read(4096))
|
||||||
|
|
||||||
|
|
||||||
def get_source_file_diff(dir, filename, rev, oldfilename = None, olddir = None, origfilename = None):
|
def get_source_file_diff(dir, filename, rev, oldfilename = None, olddir = None, origfilename = None):
|
||||||
@ -2287,11 +2287,11 @@ def get_source_file_diff(dir, filename, rev, oldfilename = None, olddir = None,
|
|||||||
file1 = os.path.join(olddir, oldfilename) # old/stored original
|
file1 = os.path.join(olddir, oldfilename) # old/stored original
|
||||||
file2 = os.path.join(dir, filename) # working copy
|
file2 = os.path.join(dir, filename) # working copy
|
||||||
|
|
||||||
f1 = open(file1, 'r')
|
f1 = open(file1, 'rb')
|
||||||
s1 = f1.read()
|
s1 = f1.read()
|
||||||
f1.close()
|
f1.close()
|
||||||
|
|
||||||
f2 = open(file2, 'r')
|
f2 = open(file2, 'rb')
|
||||||
s2 = f2.read()
|
s2 = f2.read()
|
||||||
f2.close()
|
f2.close()
|
||||||
|
|
||||||
@ -3497,7 +3497,7 @@ def data_from_rpm(rpm_file, *rpmdata):
|
|||||||
import rpm
|
import rpm
|
||||||
ts = rpm.TransactionSet()
|
ts = rpm.TransactionSet()
|
||||||
ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
|
ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
|
||||||
file = open(rpm_file, 'r')
|
file = open(rpm_file, 'rb')
|
||||||
header = ts.hdrFromFdno(file.fileno())
|
header = ts.hdrFromFdno(file.fileno())
|
||||||
file.close()
|
file.close()
|
||||||
data = {}
|
data = {}
|
||||||
@ -3516,7 +3516,7 @@ def data_from_rpm(rpm_file, *rpmdata):
|
|||||||
def is_rpm(f):
|
def is_rpm(f):
|
||||||
"""check if the named file is an RPM package"""
|
"""check if the named file is an RPM package"""
|
||||||
try:
|
try:
|
||||||
h = open(f).read(4)
|
h = open(f, 'rb').read(4)
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -3532,7 +3532,7 @@ def is_srcrpm(f):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
h = open(f).read(8)
|
h = open(f, 'rb').read(8)
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user