mirror of
https://github.com/openSUSE/osc.git
synced 2025-10-17 22:22:51 +02:00
switched to central decode function
* util/helper.py - new decode_it function. Takes obj and checks if it is not a str. The it tries to guess the encoding based on the module chardet * all other modules: - switched from var.decode('utf-8') to decode_it(var) if possible
This commit is contained in:
@@ -16,6 +16,7 @@ from osc import oscerr
|
|||||||
from .oscsslexcp import NoSecureSSLError
|
from .oscsslexcp import NoSecureSSLError
|
||||||
from osc.util.cpio import CpioError
|
from osc.util.cpio import CpioError
|
||||||
from osc.util.packagequery import PackageError
|
from osc.util.packagequery import PackageError
|
||||||
|
from osc.util.helper import decode_it
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from M2Crypto.SSL.Checker import SSLVerificationError
|
from M2Crypto.SSL.Checker import SSLVerificationError
|
||||||
@@ -116,7 +117,7 @@ def run(prg, argv=None):
|
|||||||
msg = body.split(b'<summary>')[1]
|
msg = body.split(b'<summary>')[1]
|
||||||
msg = msg.split(b'</summary>')[0]
|
msg = msg.split(b'</summary>')[0]
|
||||||
msg = msg.replace(b'<', b'<').replace(b'>' , b'>').replace(b'&', b'&')
|
msg = msg.replace(b'<', b'<').replace(b'>' , b'>').replace(b'&', b'&')
|
||||||
print(msg.decode('utf-8'), file=sys.stderr)
|
print(decode_it(msg), file=sys.stderr)
|
||||||
if e.code >= 500 and e.code <= 599:
|
if e.code >= 500 and e.code <= 599:
|
||||||
print('\nRequest: %s' % e.filename)
|
print('\nRequest: %s' % e.filename)
|
||||||
print('Headers:')
|
print('Headers:')
|
||||||
|
17
osc/build.py
17
osc/build.py
@@ -21,8 +21,9 @@ except ImportError:
|
|||||||
from tempfile import NamedTemporaryFile, mkdtemp
|
from tempfile import NamedTemporaryFile, mkdtemp
|
||||||
from osc.fetch import *
|
from osc.fetch import *
|
||||||
from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir, dgst
|
from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir, dgst
|
||||||
from osc.core import get_binarylist, get_binary_file, run_external, return_external, raw_input, decode_it
|
from osc.core import get_binarylist, get_binary_file, run_external, return_external, raw_input
|
||||||
from osc.util import rpmquery, debquery, archquery
|
from osc.util import rpmquery, debquery, archquery
|
||||||
|
from osc.util.helper import decode_it
|
||||||
import osc.conf
|
import osc.conf
|
||||||
from . import oscerr
|
from . import oscerr
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -772,13 +773,13 @@ def main(apiurl, opts, argv):
|
|||||||
else:
|
else:
|
||||||
print('Getting buildinfo from server and store to %s' % bi_filename)
|
print('Getting buildinfo from server and store to %s' % bi_filename)
|
||||||
|
|
||||||
bi_text = get_buildinfo(apiurl,
|
bi_text = decode_it(get_buildinfo(apiurl,
|
||||||
prj,
|
prj,
|
||||||
pac,
|
pac,
|
||||||
repo,
|
repo,
|
||||||
arch,
|
arch,
|
||||||
specfile=build_descr_data,
|
specfile=build_descr_data,
|
||||||
addlist=extra_pkgs).decode('utf-8')
|
addlist=extra_pkgs))
|
||||||
if not bi_file:
|
if not bi_file:
|
||||||
bi_file = open(bi_filename, 'w')
|
bi_file = open(bi_filename, 'w')
|
||||||
# maybe we should check for errors before saving the file
|
# maybe we should check for errors before saving the file
|
||||||
@@ -788,7 +789,7 @@ def main(apiurl, opts, argv):
|
|||||||
bc = get_buildconfig(apiurl, prj, repo)
|
bc = get_buildconfig(apiurl, prj, repo)
|
||||||
if not bc_file:
|
if not bc_file:
|
||||||
bc_file = open(bc_filename, 'w')
|
bc_file = open(bc_filename, 'w')
|
||||||
bc_file.write(bc.decode('utf-8'))
|
bc_file.write(decode_it(bc))
|
||||||
bc_file.flush()
|
bc_file.flush()
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
@@ -819,7 +820,7 @@ def main(apiurl, opts, argv):
|
|||||||
# Set default binary type if cannot be detected
|
# Set default binary type if cannot be detected
|
||||||
binary_type = 'rpm'
|
binary_type = 'rpm'
|
||||||
if os.path.exists('/usr/lib/build/queryconfig'):
|
if os.path.exists('/usr/lib/build/queryconfig'):
|
||||||
binary_type = return_external('/usr/lib/build/queryconfig', '--dist', bc_filename, 'binarytype').decode('utf-8').strip()
|
binary_type = decode_it(return_external('/usr/lib/build/queryconfig', '--dist', bc_filename, 'binarytype')).strip()
|
||||||
# If binary type is set to a useless value, reset to 'rpm'
|
# If binary type is set to a useless value, reset to 'rpm'
|
||||||
if binary_type == 'UNDEFINED':
|
if binary_type == 'UNDEFINED':
|
||||||
binary_type = 'rpm'
|
binary_type = 'rpm'
|
||||||
@@ -1247,13 +1248,13 @@ def main(apiurl, opts, argv):
|
|||||||
(s_built, b_built) = get_built_files(pacdir, bi.buildtype)
|
(s_built, b_built) = get_built_files(pacdir, bi.buildtype)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
if s_built: print(s_built.decode('utf-8'))
|
if s_built: print(decode_it(s_built))
|
||||||
print()
|
print()
|
||||||
print(b_built.decode('utf-8'))
|
print(decode_it(b_built))
|
||||||
|
|
||||||
if opts.keep_pkgs:
|
if opts.keep_pkgs:
|
||||||
for i in b_built.splitlines() + s_built.splitlines():
|
for i in b_built.splitlines() + s_built.splitlines():
|
||||||
shutil.copy2(i, os.path.join(opts.keep_pkgs, os.path.basename(i.decode('utf-8'))))
|
shutil.copy2(i, os.path.join(opts.keep_pkgs, os.path.basename(decode_it(i))))
|
||||||
|
|
||||||
if bi_file:
|
if bi_file:
|
||||||
bi_file.close()
|
bi_file.close()
|
||||||
|
@@ -759,7 +759,7 @@ class Osc(cmdln.Cmdln):
|
|||||||
buf = f.read(16384)
|
buf = f.read(16384)
|
||||||
if not buf:
|
if not buf:
|
||||||
break
|
break
|
||||||
sys.stdout.write(buf.decode('utf-8'))
|
sys.stdout.write(decode_it(buf))
|
||||||
|
|
||||||
elif opts.delete:
|
elif opts.delete:
|
||||||
print("Delete token")
|
print("Delete token")
|
||||||
@@ -779,7 +779,7 @@ class Osc(cmdln.Cmdln):
|
|||||||
raise oscerr.WrongArgs("Did you mean --" + args[0] + "?")
|
raise oscerr.WrongArgs("Did you mean --" + args[0] + "?")
|
||||||
# just list token
|
# just list token
|
||||||
for data in streamfile(url, http_GET):
|
for data in streamfile(url, http_GET):
|
||||||
sys.stdout.write(data.decode('utf-8'))
|
sys.stdout.write(decode_it(data))
|
||||||
|
|
||||||
|
|
||||||
@cmdln.option('-a', '--attribute', metavar='ATTRIBUTE',
|
@cmdln.option('-a', '--attribute', metavar='ATTRIBUTE',
|
||||||
@@ -944,22 +944,22 @@ class Osc(cmdln.Cmdln):
|
|||||||
# show
|
# show
|
||||||
if not opts.edit and not opts.file and not opts.delete and not opts.create and not opts.set:
|
if not opts.edit and not opts.file and not opts.delete and not opts.create and not opts.set:
|
||||||
if cmd == 'prj':
|
if cmd == 'prj':
|
||||||
sys.stdout.write(b''.join(show_project_meta(apiurl, project, rev=opts.revision, blame=opts.blame)).decode('utf-8'))
|
sys.stdout.write(decode_it(b''.join(show_project_meta(apiurl, project, rev=opts.revision, blame=opts.blame))))
|
||||||
elif cmd == 'pkg':
|
elif cmd == 'pkg':
|
||||||
sys.stdout.write(b''.join(show_package_meta(apiurl, project, package, blame=opts.blame)).decode('utf-8'))
|
sys.stdout.write(decode_it(b''.join(show_package_meta(apiurl, project, package, blame=opts.blame))))
|
||||||
elif cmd == 'attribute':
|
elif cmd == 'attribute':
|
||||||
sys.stdout.write(b''.join(show_attribute_meta(apiurl, project, package, subpackage,
|
sys.stdout.write(decode_it(b''.join(show_attribute_meta(apiurl, project, package, subpackage,
|
||||||
opts.attribute, opts.attribute_defaults, opts.attribute_project)).decode('utf-8'))
|
opts.attribute, opts.attribute_defaults, opts.attribute_project))))
|
||||||
elif cmd == 'prjconf':
|
elif cmd == 'prjconf':
|
||||||
sys.stdout.write(b''.join(show_project_conf(apiurl, project, rev=opts.revision, blame=opts.blame)).decode('utf-8'))
|
sys.stdout.write(decode_it(b''.join(show_project_conf(apiurl, project, rev=opts.revision, blame=opts.blame))))
|
||||||
elif cmd == 'user':
|
elif cmd == 'user':
|
||||||
r = get_user_meta(apiurl, user)
|
r = get_user_meta(apiurl, user)
|
||||||
if r:
|
if r:
|
||||||
sys.stdout.write(b''.join(r).decode('utf-8'))
|
sys.stdout.write(decode_it(b''.join(r)))
|
||||||
elif cmd == 'group':
|
elif cmd == 'group':
|
||||||
r = get_group_meta(apiurl, group)
|
r = get_group_meta(apiurl, group)
|
||||||
if r:
|
if r:
|
||||||
sys.stdout.write(b''.join(r).decode('utf-8'))
|
sys.stdout.write(decode_it(b''.join(r)))
|
||||||
elif cmd == 'pattern':
|
elif cmd == 'pattern':
|
||||||
if pattern:
|
if pattern:
|
||||||
r = show_pattern_meta(apiurl, project, pattern)
|
r = show_pattern_meta(apiurl, project, pattern)
|
||||||
@@ -1396,9 +1396,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
if opts.diff or not opts.message:
|
if opts.diff or not opts.message:
|
||||||
try:
|
try:
|
||||||
rdiff = 'old: %s/%s\nnew: %s/%s rev %s\n' % (dst_project, dst_package, src_project, src_package, rev)
|
rdiff = 'old: %s/%s\nnew: %s/%s rev %s\n' % (dst_project, dst_package, src_project, src_package, rev)
|
||||||
rdiff += server_diff(apiurl,
|
rdiff += decode_it(server_diff(apiurl,
|
||||||
dst_project, dst_package, None,
|
dst_project, dst_package, None,
|
||||||
src_project, src_package, rev, True).decode('utf-8')
|
src_project, src_package, rev, True))
|
||||||
except:
|
except:
|
||||||
rdiff = ''
|
rdiff = ''
|
||||||
|
|
||||||
@@ -2484,7 +2484,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
action.tgt_project, action.tgt_package)
|
action.tgt_project, action.tgt_package)
|
||||||
diff += submit_action_diff(apiurl, action)
|
diff += submit_action_diff(apiurl, action)
|
||||||
diff += '\n\n'
|
diff += '\n\n'
|
||||||
run_pager(diff.decode('utf-8'), tmp_suffix='')
|
run_pager(decode_it(diff), tmp_suffix='')
|
||||||
|
|
||||||
# checkout
|
# checkout
|
||||||
elif cmd == 'checkout' or cmd == 'co':
|
elif cmd == 'checkout' or cmd == 'co':
|
||||||
@@ -2984,7 +2984,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
revision=rev,
|
revision=rev,
|
||||||
comment=comment,
|
comment=comment,
|
||||||
keep_link=opts.keep_link)
|
keep_link=opts.keep_link)
|
||||||
print(r.decode('utf-8'))
|
print(decode_it(r))
|
||||||
|
|
||||||
|
|
||||||
@cmdln.option('-r', '--repo', metavar='REPO',
|
@cmdln.option('-r', '--repo', metavar='REPO',
|
||||||
@@ -3851,9 +3851,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
for i in pac.get_diff(rev1):
|
for i in pac.get_diff(rev1):
|
||||||
diff += ''.join(i)
|
diff += ''.join(i)
|
||||||
else:
|
else:
|
||||||
diff += server_diff_noex(pac.apiurl, pac.prjname, pac.name, rev1,
|
diff += decode_it(server_diff_noex(pac.apiurl, pac.prjname, pac.name, rev1,
|
||||||
pac.prjname, pac.name, rev2,
|
pac.prjname, pac.name, rev2,
|
||||||
not opts.plain, opts.missingok, opts.meta, not opts.unexpand).decode('utf-8')
|
not opts.plain, opts.missingok, opts.meta, not opts.unexpand))
|
||||||
run_pager(diff)
|
run_pager(diff)
|
||||||
|
|
||||||
|
|
||||||
@@ -4134,10 +4134,10 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
close_fds=True)
|
close_fds=True)
|
||||||
p.stdin.write(rdiff)
|
p.stdin.write(rdiff)
|
||||||
p.stdin.close()
|
p.stdin.close()
|
||||||
print("".join(x.decode() for x in p.stdout.readlines()))
|
print("".join(decode_it(x) for x in p.stdout.readlines()))
|
||||||
elif opts.unified:
|
elif opts.unified:
|
||||||
print()
|
print()
|
||||||
print(rdiff.decode('utf-8'))
|
print(decode_it(rdiff))
|
||||||
#run_pager(rdiff)
|
#run_pager(rdiff)
|
||||||
|
|
||||||
def _prdiff_output_matching_requests(self, opts, requests,
|
def _prdiff_output_matching_requests(self, opts, requests,
|
||||||
@@ -5330,7 +5330,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
else:
|
else:
|
||||||
raise oscerr.WrongArgs('please provide project package repository arch.')
|
raise oscerr.WrongArgs('please provide project package repository arch.')
|
||||||
|
|
||||||
print(get_rpmlint_log(apiurl, project, package, repository, arch).decode('utf-8'))
|
print(decode_it(get_rpmlint_log(apiurl, project, package, repository, arch)))
|
||||||
|
|
||||||
@cmdln.alias('bl')
|
@cmdln.alias('bl')
|
||||||
@cmdln.alias('blt')
|
@cmdln.alias('blt')
|
||||||
@@ -5788,11 +5788,11 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
if opts.multibuild_package:
|
if opts.multibuild_package:
|
||||||
package = package + ":" + opts.multibuild_package
|
package = package + ":" + opts.multibuild_package
|
||||||
|
|
||||||
print(get_buildinfo(apiurl,
|
print(decode_it(get_buildinfo(apiurl,
|
||||||
project, package, repository, arch,
|
project, package, repository, arch,
|
||||||
specfile=build_descr_data,
|
specfile=build_descr_data,
|
||||||
debug=opts.debug,
|
debug=opts.debug,
|
||||||
addlist=opts.extra_pkgs).decode('utf-8'))
|
addlist=opts.extra_pkgs)))
|
||||||
|
|
||||||
|
|
||||||
def do_buildconfig(self, subcmd, opts, *args):
|
def do_buildconfig(self, subcmd, opts, *args):
|
||||||
@@ -5835,7 +5835,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
else:
|
else:
|
||||||
raise oscerr.WrongArgs('Wrong number of arguments.')
|
raise oscerr.WrongArgs('Wrong number of arguments.')
|
||||||
|
|
||||||
print(get_buildconfig(apiurl, project, repository).decode('utf-8'))
|
print(decode_it(get_buildconfig(apiurl, project, repository)))
|
||||||
|
|
||||||
|
|
||||||
def do_workerinfo(self, subcmd, opts, worker):
|
def do_workerinfo(self, subcmd, opts, worker):
|
||||||
@@ -6077,8 +6077,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
recipe = recipe.strip()
|
recipe = recipe.strip()
|
||||||
if recipe == 'arch':
|
if recipe == 'arch':
|
||||||
recipe = 'PKGBUILD'
|
recipe = 'PKGBUILD'
|
||||||
if not isinstance(recipe, str):
|
recipe = decode_it(recipe)
|
||||||
recipe = recipe.decode('utf8')
|
|
||||||
pac = os.path.basename(os.getcwd())
|
pac = os.path.basename(os.getcwd())
|
||||||
if is_package_dir(os.getcwd()):
|
if is_package_dir(os.getcwd()):
|
||||||
pac = store_read_package(os.getcwd())
|
pac = store_read_package(os.getcwd())
|
||||||
@@ -7945,7 +7944,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
data=opts.data,
|
data=opts.data,
|
||||||
file=opts.file,
|
file=opts.file,
|
||||||
headers=opts.headers)
|
headers=opts.headers)
|
||||||
out = r.read().decode('utf-8')
|
out = decode_it(r.read())
|
||||||
|
|
||||||
if opts.edit:
|
if opts.edit:
|
||||||
text = edit_text(out)
|
text = edit_text(out)
|
||||||
@@ -7953,7 +7952,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
url,
|
url,
|
||||||
data=text,
|
data=text,
|
||||||
headers=opts.headers)
|
headers=opts.headers)
|
||||||
out = r.read().decode('utf-8')
|
out = decode_it(r.read())
|
||||||
|
|
||||||
sys.stdout.write(out)
|
sys.stdout.write(out)
|
||||||
|
|
||||||
@@ -8354,7 +8353,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
sys.stdout.write(data)
|
sys.stdout.write(data)
|
||||||
else:
|
else:
|
||||||
sys.stdout.write(data.decode('utf-8'))
|
sys.stdout.write(decode_it(data))
|
||||||
|
|
||||||
|
|
||||||
# helper function to download a file from a specific revision
|
# helper function to download a file from a specific revision
|
||||||
@@ -8776,7 +8775,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
buf = f.read(16384)
|
buf = f.read(16384)
|
||||||
if not buf:
|
if not buf:
|
||||||
break
|
break
|
||||||
sys.stdout.write(buf.decode('utf-8'))
|
sys.stdout.write(decode_it(buf))
|
||||||
|
|
||||||
@cmdln.option('-m', '--message',
|
@cmdln.option('-m', '--message',
|
||||||
help='add MESSAGE to changes (do not open an editor)')
|
help='add MESSAGE to changes (do not open an editor)')
|
||||||
|
31
osc/core.py
31
osc/core.py
@@ -55,7 +55,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from .util.helper import cmp_to_key
|
from .util.helper import cmp_to_key
|
||||||
|
|
||||||
from .util.helper import decode_list
|
from osc.util.helper import decode_list, decode_it
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# python 2.6 and python 2.7
|
# python 2.6 and python 2.7
|
||||||
@@ -256,17 +256,6 @@ buildstatus_symbols = {'succeeded': '.',
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def decode_it(obj):
|
|
||||||
if isinstance(obj, str):
|
|
||||||
return obj
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
import chardet
|
|
||||||
return obj.decode(chardet.detect(obj)['encoding'])
|
|
||||||
except:
|
|
||||||
import locale
|
|
||||||
return obj.decode(locale.getlocale()[1])
|
|
||||||
|
|
||||||
# os.path.samefile is available only under Unix
|
# os.path.samefile is available only under Unix
|
||||||
def os_path_samefile(path1, path2):
|
def os_path_samefile(path1, path2):
|
||||||
try:
|
try:
|
||||||
@@ -2146,7 +2135,7 @@ rev: %s
|
|||||||
|
|
||||||
if not force:
|
if not force:
|
||||||
print('*' * 36, 'old', '*' * 36)
|
print('*' * 36, 'old', '*' * 36)
|
||||||
print(m.decode('utf-8'))
|
print(decode_it(m))
|
||||||
print('*' * 36, 'new', '*' * 36)
|
print('*' * 36, 'new', '*' * 36)
|
||||||
print(ET.tostring(root, encoding=ET_ENCODING))
|
print(ET.tostring(root, encoding=ET_ENCODING))
|
||||||
print('*' * 72)
|
print('*' * 72)
|
||||||
@@ -3823,7 +3812,7 @@ def edit_meta(metatype,
|
|||||||
# So we need the following even if it is ugly.
|
# So we need the following even if it is ugly.
|
||||||
if sys.version_info >= (3, 0):
|
if sys.version_info >= (3, 0):
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
data = data.decode('utf-8')
|
data = decode_it(data)
|
||||||
orgprj = ET.fromstring(''.join(data)).get('project')
|
orgprj = ET.fromstring(''.join(data)).get('project')
|
||||||
elif isinstance(data, list):
|
elif isinstance(data, list):
|
||||||
decode_data = decode_list(data)
|
decode_data = decode_list(data)
|
||||||
@@ -4852,7 +4841,7 @@ def server_diff_noex(apiurl,
|
|||||||
msg = None
|
msg = None
|
||||||
body = None
|
body = None
|
||||||
try:
|
try:
|
||||||
body = e.read().decode('utf-8')
|
body = decode_it(e.read())
|
||||||
if not 'bad link' in body:
|
if not 'bad link' in body:
|
||||||
return '# diff failed: ' + body
|
return '# diff failed: ' + body
|
||||||
except:
|
except:
|
||||||
@@ -6166,7 +6155,7 @@ def get_worker_info(apiurl, worker):
|
|||||||
u = makeurl(apiurl, ['worker', worker])
|
u = makeurl(apiurl, ['worker', worker])
|
||||||
f = http_GET(u)
|
f = http_GET(u)
|
||||||
|
|
||||||
return f.read().decode('utf-8')
|
return decode_it(f.read())
|
||||||
|
|
||||||
|
|
||||||
def check_constraints(apiurl, prj, repository, arch, package, constraintsfile=None):
|
def check_constraints(apiurl, prj, repository, arch, package, constraintsfile=None):
|
||||||
@@ -6341,10 +6330,10 @@ def get_commitlog(apiurl, prj, package, revision, format = 'text', meta = False,
|
|||||||
r.append('</logentry>')
|
r.append('</logentry>')
|
||||||
else:
|
else:
|
||||||
if requestid:
|
if requestid:
|
||||||
requestid = (b"rq" + requestid).decode('utf-8')
|
requestid = decode_it((b"rq" + requestid))
|
||||||
s = '-' * 76 + \
|
s = '-' * 76 + \
|
||||||
'\nr%s | %s | %s | %s | %s | %s\n' % (rev, user, t, srcmd5, version, requestid) + \
|
'\nr%s | %s | %s | %s | %s | %s\n' % (rev, user, t, srcmd5, version, requestid) + \
|
||||||
'\n' + comment.decode('utf-8')
|
'\n' + decode_it(comment)
|
||||||
r.append(s)
|
r.append(s)
|
||||||
|
|
||||||
if format not in ['csv', 'xml']:
|
if format not in ['csv', 'xml']:
|
||||||
@@ -6479,7 +6468,7 @@ def store_write_string(dir, file, string, subdir=''):
|
|||||||
try:
|
try:
|
||||||
f = open(fname + '.new', 'w')
|
f = open(fname + '.new', 'w')
|
||||||
if not isinstance(string, str):
|
if not isinstance(string, str):
|
||||||
string = string.decode('utf-8')
|
string = decode_it(string)
|
||||||
f.write(string)
|
f.write(string)
|
||||||
f.close()
|
f.close()
|
||||||
os.rename(fname + '.new', fname)
|
os.rename(fname + '.new', fname)
|
||||||
@@ -7341,7 +7330,7 @@ def request_interactive_review(apiurl, request, initial_cmd='', group=None,
|
|||||||
except (ValueError, IndexError):
|
except (ValueError, IndexError):
|
||||||
print('Invalid rpmlintlog index. Please choose between 0 and %i' % (len(lintlogs)-1))
|
print('Invalid rpmlintlog index. Please choose between 0 and %i' % (len(lintlogs)-1))
|
||||||
try:
|
try:
|
||||||
print(get_rpmlint_log(apiurl, **lintlogs[lint_n]).decode('utf-8'))
|
print(decode_it(get_rpmlint_log(apiurl, **lintlogs[lint_n])))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
print('No rpmlintlog for %s %s' % (lintlogs[lint_n]['repo'],
|
print('No rpmlintlog for %s %s' % (lintlogs[lint_n]['repo'],
|
||||||
@@ -7422,7 +7411,7 @@ def request_interactive_review(apiurl, request, initial_cmd='', group=None,
|
|||||||
tmpfile.write(issues)
|
tmpfile.write(issues)
|
||||||
try:
|
try:
|
||||||
diff = request_diff(apiurl, request.reqid)
|
diff = request_diff(apiurl, request.reqid)
|
||||||
tmpfile.write(diff.decode('utf-8'))
|
tmpfile.write(decode_it(diff))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
if e.code != 400:
|
if e.code != 400:
|
||||||
raise
|
raise
|
||||||
|
@@ -27,6 +27,8 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from io import BytesIO as MyIO
|
from io import BytesIO as MyIO
|
||||||
|
|
||||||
|
from osc.util.helper import decode_it
|
||||||
|
|
||||||
# workaround for python24
|
# workaround for python24
|
||||||
if not hasattr(os, 'SEEK_SET'):
|
if not hasattr(os, 'SEEK_SET'):
|
||||||
os.SEEK_SET = 0
|
os.SEEK_SET = 0
|
||||||
@@ -189,7 +191,7 @@ class Ar:
|
|||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
pos += self.hdr_len
|
pos += self.hdr_len
|
||||||
m = self.hdr_pat.search(data.decode('utf-8'))
|
m = self.hdr_pat.search(decode_it(data))
|
||||||
if not m:
|
if not m:
|
||||||
raise ArError(self.filename, 'unexpected hdr entry')
|
raise ArError(self.filename, 'unexpected hdr entry')
|
||||||
args = m.groups() + (pos, )
|
args = m.groups() + (pos, )
|
||||||
|
@@ -6,6 +6,7 @@ import re
|
|||||||
import tarfile
|
import tarfile
|
||||||
from . import packagequery
|
from . import packagequery
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from osc.util.helper import decode_it
|
||||||
|
|
||||||
class ArchError(packagequery.PackageError):
|
class ArchError(packagequery.PackageError):
|
||||||
pass
|
pass
|
||||||
@@ -31,8 +32,8 @@ class ArchQuery(packagequery.PackageQuery, packagequery.PackageQueryResult):
|
|||||||
line = line.rstrip().split(b' = ', 2)
|
line = line.rstrip().split(b' = ', 2)
|
||||||
if len(line) == 2:
|
if len(line) == 2:
|
||||||
if not line[0] in self.fields:
|
if not line[0] in self.fields:
|
||||||
self.fields[line[0].decode('utf-8')] = []
|
self.fields[decode_it(line[0])] = []
|
||||||
self.fields[line[0].decode('utf-8')].append(line[1])
|
self.fields[decode_it(line[0])].append(line[1])
|
||||||
if self_provides:
|
if self_provides:
|
||||||
prv = '%s = %s' % (self.name(), self.fields['pkgver'][0])
|
prv = '%s = %s' % (self.name(), self.fields['pkgver'][0])
|
||||||
self.fields.setdefault('provides', []).append(prv)
|
self.fields.setdefault('provides', []).append(prv)
|
||||||
@@ -116,7 +117,7 @@ class ArchQuery(packagequery.PackageQuery, packagequery.PackageQueryResult):
|
|||||||
def canonname(self):
|
def canonname(self):
|
||||||
pkgver = self.fields['pkgver'][0] if 'pkgver' in self.fields else None
|
pkgver = self.fields['pkgver'][0] if 'pkgver' in self.fields else None
|
||||||
canonname = self.name() + b'-' + pkgver + b'-' + self.arch() + b'.' + self.pkgsuffix
|
canonname = self.name() + b'-' + pkgver + b'-' + self.arch() + b'.' + self.pkgsuffix
|
||||||
return canonname.decode('utf-8')
|
return decode_it(canonname)
|
||||||
|
|
||||||
def gettag(self, tag):
|
def gettag(self, tag):
|
||||||
# implement me, if needed
|
# implement me, if needed
|
||||||
|
@@ -21,6 +21,8 @@ import stat
|
|||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from osc.util.helper import decode_it
|
||||||
|
|
||||||
# workaround for python24
|
# workaround for python24
|
||||||
if not hasattr(os, 'SEEK_SET'):
|
if not hasattr(os, 'SEEK_SET'):
|
||||||
os.SEEK_SET = 0
|
os.SEEK_SET = 0
|
||||||
@@ -161,7 +163,7 @@ class CpioRead:
|
|||||||
self.__file.seek(0, os.SEEK_SET)
|
self.__file.seek(0, os.SEEK_SET)
|
||||||
self._init_datastructs()
|
self._init_datastructs()
|
||||||
data = self.__file.read(6)
|
data = self.__file.read(6)
|
||||||
self.format = data.decode('utf-8')
|
self.format = decode_it(data)
|
||||||
if not self.format in self.sfmt.values():
|
if not self.format in self.sfmt.values():
|
||||||
raise CpioError(self.filename, '\'%s\' is not a supported cpio format' % self.format)
|
raise CpioError(self.filename, '\'%s\' is not a supported cpio format' % self.format)
|
||||||
pos = 0
|
pos = 0
|
||||||
@@ -173,7 +175,7 @@ class CpioRead:
|
|||||||
pos += self.hdr_len
|
pos += self.hdr_len
|
||||||
data = struct.unpack(self.hdr_fmt, data)
|
data = struct.unpack(self.hdr_fmt, data)
|
||||||
hdr = CpioHdr(*data)
|
hdr = CpioHdr(*data)
|
||||||
hdr.filename = self.__file.read(hdr.namesize - 1).decode('utf-8')
|
hdr.filename = decode_it(self.__file.read(hdr.namesize - 1))
|
||||||
if hdr.filename == 'TRAILER!!!':
|
if hdr.filename == 'TRAILER!!!':
|
||||||
break
|
break
|
||||||
pos += hdr.namesize
|
pos += hdr.namesize
|
||||||
@@ -240,7 +242,7 @@ class CpioWrite:
|
|||||||
if isinstance(content, str):
|
if isinstance(content, str):
|
||||||
c.append(content)
|
c.append(content)
|
||||||
else:
|
else:
|
||||||
c.append(content.decode('utf-8'))
|
c.append(decode_it(content))
|
||||||
|
|
||||||
c = ''.join(c)
|
c = ''.join(c)
|
||||||
if len(c) % 4:
|
if len(c) % 4:
|
||||||
|
@@ -10,6 +10,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import StringIO
|
import StringIO
|
||||||
from . import packagequery
|
from . import packagequery
|
||||||
|
from osc.util.helper import decode_it
|
||||||
|
|
||||||
HAVE_LZMA = True
|
HAVE_LZMA = True
|
||||||
try:
|
try:
|
||||||
@@ -73,7 +74,7 @@ class DebQuery(packagequery.PackageQuery, packagequery.PackageQueryResult):
|
|||||||
val += b'\n' + data.strip()
|
val += b'\n' + data.strip()
|
||||||
data = control.readline().rstrip()
|
data = control.readline().rstrip()
|
||||||
field = field.replace(b'-', b'_').lower()
|
field = field.replace(b'-', b'_').lower()
|
||||||
field = field.decode('utf-8')
|
field = decode_it(field)
|
||||||
if field in self.default_tags + extra_tags or all_tags:
|
if field in self.default_tags + extra_tags or all_tags:
|
||||||
# a hyphen is not allowed in dict keys
|
# a hyphen is not allowed in dict keys
|
||||||
self.fields[field] = val
|
self.fields[field] = val
|
||||||
|
@@ -43,7 +43,23 @@ def decode_list(ilist):
|
|||||||
dlist = []
|
dlist = []
|
||||||
for elem in ilist:
|
for elem in ilist:
|
||||||
if not isinstance(elem, str):
|
if not isinstance(elem, str):
|
||||||
dlist.append(elem.decode('utf-8'))
|
dlist.append(decode_it(elem))
|
||||||
else:
|
else:
|
||||||
dlist.append(elem)
|
dlist.append(elem)
|
||||||
return dlist
|
return dlist
|
||||||
|
|
||||||
|
|
||||||
|
def decode_it(obj):
|
||||||
|
""" Decodes the given object if obj is not a string
|
||||||
|
based on the chardet module if possible
|
||||||
|
"""
|
||||||
|
|
||||||
|
if isinstance(obj, str):
|
||||||
|
return obj
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
import chardet
|
||||||
|
return obj.decode(chardet.detect(obj)['encoding'])
|
||||||
|
except:
|
||||||
|
import locale
|
||||||
|
return obj.decode(locale.getlocale()[1])
|
||||||
|
Reference in New Issue
Block a user