Remove most subprocess bufsize and open buffering options to instead use defaults. Addresses several RuntimeWarnings when using Python 3.8.

This commit is contained in:
Greg Neagle
2020-08-06 21:34:43 -07:00
parent d1cc652f5d
commit bee2216e8d
8 changed files with 12 additions and 13 deletions

View File

@@ -293,7 +293,7 @@ def get_catalog_info_from_dmg(dmgpath, options):
def readfile(path):
'''Reads file at path. Returns a string.'''
try:
fileobject = open(os.path.expanduser(path), mode='r', buffering=1)
fileobject = open(os.path.expanduser(path), mode='r')
data = fileobject.read()
fileobject.close()
return data

View File

@@ -257,7 +257,7 @@ def run_adobe_install_tool(
# indeterminate progress bar
munkistatus.percent(-1)
proc = subprocess.Popen(cmd, shell=False, bufsize=1,
proc = subprocess.Popen(cmd, shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@@ -386,7 +386,7 @@ def writefile(stringdata, path):
'''Writes string data to path.
Returns the path on success, empty string on failure.'''
try:
fileobject = open(path, mode='w', buffering=1)
fileobject = open(path, mode='wb')
print(stringdata.encode('UTF-8'), file=fileobject)
fileobject.close()
return path
@@ -729,7 +729,7 @@ def update_acrobatpro(dmgpath):
app_list = []
app_list_file = os.path.join(resources_dir, 'app_list.txt')
if os.path.exists(app_list_file):
fileobj = open(app_list_file, mode='r', buffering=-1)
fileobj = open(app_list_file, mode='r')
if fileobj:
for line in fileobj.readlines():
app_list.append(line)

View File

@@ -234,7 +234,7 @@ class AppleUpdates(object):
# pylint: disable=no-self-use
cmd = ['/usr/sbin/pkgutil', '--regexp', '--pkg-info-plist',
r'com\.apple\.*']
proc = subprocess.Popen(cmd, shell=False, bufsize=1,
proc = subprocess.Popen(cmd, shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = proc.communicate()[0] # don't decode because we need the bytes

View File

@@ -60,7 +60,7 @@ def log(msg, logname=''):
else:
logpath = os.path.join(os.path.dirname(prefs.pref('LogFile')), logname)
try:
fileobj = codecs.open(logpath, mode='a', buffering=1, encoding='UTF-8')
fileobj = codecs.open(logpath, mode='a', encoding='UTF-8')
try:
fileobj.write("%s %s\n" % (time.strftime(formatstr), msg))
except (OSError, IOError):

View File

@@ -140,7 +140,7 @@ def currentGUIusers():
def pythonScriptRunning(scriptname):
"""Returns Process ID for a running python script"""
cmd = ['/bin/ps', '-eo', 'pid=,command=']
proc = subprocess.Popen(cmd, shell=False, bufsize=1,
proc = subprocess.Popen(cmd, shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = proc.communicate()[0].decode("UTF-8")
@@ -176,7 +176,7 @@ def pythonScriptRunning(scriptname):
def osascript(osastring):
"""Wrapper to run AppleScript commands"""
cmd = ['/usr/bin/osascript', '-e', osastring]
proc = subprocess.Popen(cmd, shell=False, bufsize=1,
proc = subprocess.Popen(cmd, shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = proc.communicate()

View File

@@ -635,7 +635,6 @@ def getInstalledPackageVersion(pkgid):
# First check (Leopard and later) package database
proc = subprocess.Popen(['/usr/sbin/pkgutil',
'--pkg-info-plist', pkgid],
bufsize=1,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out = proc.communicate()[0]
@@ -776,7 +775,7 @@ def getChoiceChangesXML(pkgitem):
try:
proc = subprocess.Popen(
['/usr/sbin/installer', '-showChoiceChangesXML', '-pkg', pkgitem],
bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = proc.communicate()[0]
if out:
plist = FoundationPlist.readPlistFromString(out)

View File

@@ -124,7 +124,7 @@ def archive_report():
_warn('Could not archive report.')
# now keep number of archived reports to 100 or fewer
proc = subprocess.Popen(['/bin/ls', '-t1', archivepath],
bufsize=1, stdout=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output = proc.communicate()[0].decode('UTF-8')
if output:

View File

@@ -36,7 +36,7 @@ def _writefile(stringdata, path):
'''Writes string data to path.
Returns the path on success, empty string on failure.'''
try:
fileobject = open(path, mode='wb', buffering=1)
fileobject = open(path, mode='wb')
# write line-by-line to ensure proper UNIX line-endings
for line in stringdata.splitlines():
fileobject.write(line.encode('UTF-8') + b"\n")
@@ -93,7 +93,7 @@ def run_script(itemname, path, scriptname, suppress_error=False):
scriptoutput = []
try:
proc = subprocess.Popen(path, shell=False, bufsize=1,
proc = subprocess.Popen(path, shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)