From b34ed011091a8dd877572dbb7de4c5a7d3e47b86 Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 5 Mar 2020 00:08:24 +0100 Subject: [PATCH] Use print() function in both Python 2 and Python 3 Signed-off-by: cclauss --- admin/linux/debian/scripts/git2changelog.py | 20 +++++++++++++------- admin/osx/macdeployqt.py | 15 ++++++++------- admin/win/nsi/l10n/bin/build_locale_nsi.py | 13 +++++++++---- shell_integration/nautilus/syncstate.py | 1 + 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/admin/linux/debian/scripts/git2changelog.py b/admin/linux/debian/scripts/git2changelog.py index 3a1b44fb6..51c6afac0 100755 --- a/admin/linux/debian/scripts/git2changelog.py +++ b/admin/linux/debian/scripts/git2changelog.py @@ -1,5 +1,6 @@ #!//usr/bin/env python2.7 +from __future__ import print_function import subprocess import re import sys @@ -7,6 +8,11 @@ import datetime import os import ConfigParser +try: + long +except NameError: + long = int + distribution="yakkety" versionTagRE = re.compile("^v([0-9]+((\.[0-9]+)+))(-(.+))?$") @@ -123,12 +129,12 @@ def genChangeLogEntries(f, entries, distribution): version = upstreamVersion else: version = upstreamVersion + "~" + distribution + "1" - print >> f, "nextcloud-client (%s) %s; urgency=medium" % (version, distribution) - print >> f - print >> f, " * " + subject - print >> f - print >> f, " -- %s <%s> %s" % (name, email, date) - print >> f + print("nextcloud-client (%s) %s; urgency=medium" % (version, distribution), file=f) + print(file=f) + print(" * " + subject, file=f) + print(file=f) + print(" -- %s <%s> %s" % (name, email, date), file=f) + print(file=f) return (latestBaseVersion, latestKind) if __name__ == "__main__": @@ -141,4 +147,4 @@ if __name__ == "__main__": with open(sys.argv[1], "wt") as f: (baseVersion, kind) = genChangeLogEntries(f, entries, distribution) - print baseVersion, kind + print(baseVersion, kind) diff --git a/admin/osx/macdeployqt.py b/admin/osx/macdeployqt.py index 2571b8eb9..fbf4a1952 100755 --- a/admin/osx/macdeployqt.py +++ b/admin/osx/macdeployqt.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with ownCloud. If not, see . +from __future__ import print_function import os import re import subprocess @@ -74,7 +75,7 @@ class CouldNotFindFrameworkError(Error): pass if len(sys.argv) < 3: - print 'Usage: %s ' % sys.argv[0] + print('Usage: %s ' % sys.argv[0]) exit() def is_exe(fpath): @@ -96,13 +97,13 @@ plugins_dir = os.path.join(bundle_dir, 'Contents', 'PlugIns') binaries = [i for i in glob(os.path.join(bundle_dir, 'Contents', 'MacOS', "*")) if is_exe(i)]; qt_version = QueryQMake('QT_VERSION') -print "Using Qt", qt_version +print("Using Qt", qt_version) fixed_libraries = [] fixed_frameworks = [] def WriteQtConf(): - print "Writing qt.conf..." + print("Writing qt.conf...") with open(os.path.join(resources_dir, 'qt.conf'), 'w') as f: f.write("[Paths]\nPlugins = PlugIns\n"); f.close() @@ -206,7 +207,7 @@ def FixLibrary(path): fixed_libraries.append(path) abs_path = FindLibrary(path) if abs_path == "": - print "Could not resolve %s, not fixing!" % path + print("Could not resolve %s, not fixing!" % path) return broken_libs = GetBrokenLibraries(abs_path) FixAllLibraries(broken_libs) @@ -256,7 +257,7 @@ def CopyPlugin(path, subdir): def CopyFramework(source_dylib): parts = source_dylib.split(os.sep) - print "CopyFramework:", source_dylib + print("CopyFramework:", source_dylib) for i, part in enumerate(parts): matchObj = re.match(r'(\w+\.framework)', part) if matchObj: @@ -354,9 +355,9 @@ else: commands.append(args) if len(sys.argv) <= 2: - print 'Will run %d commands:' % len(commands) + print('Will run %d commands:' % len(commands)) for command in commands: - print ' '.join(command) + print(' '.join(command)) for command in commands: p = subprocess.Popen(command) diff --git a/admin/win/nsi/l10n/bin/build_locale_nsi.py b/admin/win/nsi/l10n/bin/build_locale_nsi.py index 977f62887..bf8eda743 100755 --- a/admin/win/nsi/l10n/bin/build_locale_nsi.py +++ b/admin/win/nsi/l10n/bin/build_locale_nsi.py @@ -9,6 +9,11 @@ import os import polib from optparse import OptionParser +try: + unicode +except NameError: + unicode = str + parser = OptionParser() parser.add_option("-o", "--output", dest="output", help="Directory for localized output", default="../Shared/installer/nightly_localized.nsi") @@ -126,7 +131,7 @@ for root,dirs,files in os.walk(options.podir): if filename in localeToName: language = localeToName[filename] translationCache[language] = collections.OrderedDict() - + po = polib.pofile(os.path.join(root,file)) for entry in po.translated_entries(): # Loop through all our labels and add translation (each translation may have multiple labels) @@ -165,14 +170,14 @@ for language,translations in translationCache.iteritems(): for label,value in translations.iteritems(): NSINewLines.append( tostr('StrCpy $%s "%s"\n' % (label,value)) ) if language.upper() == options.lang.upper(): - NSIDeclarations.append( tostr('Var %s\n' % label) ) + NSIDeclarations.append( tostr('Var %s\n' % label) ) count += 1 NSIWorkingFile = open('%s/%s.nsh' % (options.output, language),"w") NSIWorkingFile.writelines(NSINewLines) NSIWorkingFile.close() print ( "%i translations merged for language '%s'"%(count,language) ) - + # Finally, let's write languages.nsh and declarations.nsh NSIWorkingFile = open('%s/languages.nsh' % options.output,"w") NSIWorkingFile.writelines(NSILanguages) @@ -181,5 +186,5 @@ NSIWorkingFile.close() NSIWorkingFile = open('%s/declarations.nsh' % options.output,"w") NSIWorkingFile.writelines(NSIDeclarations) NSIWorkingFile.close() - + print ( "NSI Localization Operation Complete" ) diff --git a/shell_integration/nautilus/syncstate.py b/shell_integration/nautilus/syncstate.py index 2d1494ca1..84a13161c 100644 --- a/shell_integration/nautilus/syncstate.py +++ b/shell_integration/nautilus/syncstate.py @@ -296,6 +296,7 @@ class MenuExtension(GObject.GObject, Nautilus.MenuProvider): state = entry['state'] state_ok = state.startswith('OK') state_sync = state.startswith('SYNC') + isDir = os.path.isdir(filename + os.sep) if state_ok: shareable = True elif state_sync and isDir: