Skip to content

Commit a07a129

Browse files
authored
Python 3 update for dropbox-cli (#68)
* Python 3 update for dropbox-cli This PR removes Python 2 runtime dependency on dropbox-cli. It still has the Python 2build time dependency.
1 parent d289974 commit a07a129

File tree

8 files changed

+434
-301
lines changed

8 files changed

+434
-301
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ src/libnautilus_dropbox_la*
2929
rpmbuild/
3030
mockout/
3131
nautilus-dropbox-*.tar.bz2
32+
.mypy_cache/
33+
.vscode/

Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ EXTRA_DIST = dropbox.in serializeimages.py dropbox.txt.in docgen.py rst2man.py
66
man_MANS = dropbox.1
77

88
dropbox: dropbox.in serializeimages.py
9-
python serializeimages.py $(PACKAGE_VERSION) $(datadir)/applications < dropbox.in > dropbox
9+
python3 serializeimages.py $(PACKAGE_VERSION) $(datadir)/applications < dropbox.in > dropbox
1010
chmod +x dropbox
1111

1212
dropbox.1: dropbox.txt.in dropbox docgen.py
13-
python docgen.py $(PACKAGE_VERSION) < dropbox.txt.in > dropbox.txt
13+
python3 docgen.py $(PACKAGE_VERSION) < dropbox.txt.in > dropbox.txt
1414
$(RST2MAN) dropbox.txt > dropbox.1
1515

1616
SUBDIRS = data src

configure.ac

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ PKG_CHECK_MODULES(NAUTILUS, libnautilus-extension >= $NAUTILUS_REQUIRED)
3030
PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED)
3131

3232
AC_PATH_PROG([PYTHON], [python])
33+
AC_PATH_PROG([PYTHON3], [python3])
3334

3435
AC_PATH_PROG([RST2MAN], [rst2man], [python rst2man.py])
3536
AC_SUBST(RST2MAN)
@@ -55,9 +56,30 @@ else
5556
fi
5657
])
5758

58-
PYTHON_CHECK_MODULE(gi, gi)
59+
AC_DEFUN([PYTHON3_CHECK_MODULE], [
60+
AC_MSG_CHECKING([for $1 on python3])
61+
62+
cat <<EOF | python3
63+
try:
64+
import $2
65+
except:
66+
exit(1)
67+
else:
68+
exit(0)
69+
EOF
70+
71+
if test $? -ne 0; then
72+
AC_MSG_RESULT([no])
73+
AC_MSG_ERROR([couldn't find $1])
74+
else
75+
AC_MSG_RESULT([yes])
76+
fi
77+
])
78+
5979
PYTHON_CHECK_MODULE(docutils, docutils)
6080

81+
PYTHON3_CHECK_MODULE(gi, gi)
82+
6183
# Make dependency CFLAGS and LIBS available
6284
AC_SUBST(NAUTILUS_CFLAGS)
6385
AC_SUBST(NAUTILUS_LIBS)

docgen.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# heeeheee
77
env = {"__name__":"__notmain__"}
8-
execfile("dropbox", env)
8+
exec(open("dropbox").read(), env)
99
commands = env["commands"]
1010

1111
f = open("AUTHORS", "r")
@@ -15,14 +15,14 @@
1515
formatted_commands = ""
1616
for cmd in commands:
1717
split = commands[cmd].__doc__.split('\n', 2)
18-
formatted_commands += split[1].decode('ascii').replace(cmd, "`%s`" % cmd).replace("dropbox", "``dropbox``")
19-
formatted_commands += split[2].decode('ascii').replace('\n', '\n | ')
18+
formatted_commands += split[1].replace(cmd, "`%s`" % cmd).replace("dropbox", "``dropbox``")
19+
formatted_commands += split[2].replace('\n', '\n | ')
2020
formatted_commands += '\n\n'
2121

2222
date = datetime.datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))).date()
2323
sys.stdout.write(sys.stdin.read().replace\
2424
('@AUTHORS@', authors).replace\
2525
('@DATE@', date.isoformat()).replace\
2626
('@PACKAGE_VERSION@', sys.argv[1]).replace\
27-
('@SYNOPSIS@', '| '+'\n| '.join(commands[cmd].__doc__.split('\n', 2)[1].decode('ascii').replace(cmd, "`%s`" % cmd).replace("dropbox", "``dropbox``") for cmd in commands)).replace\
27+
('@SYNOPSIS@', '| '+'\n| '.join(commands[cmd].__doc__.split('\n', 2)[1].replace(cmd, "`%s`" % cmd).replace("dropbox", "``dropbox``") for cmd in commands)).replace\
2828
('@COMMANDS@', formatted_commands))

0 commit comments

Comments
 (0)