mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-25 15:41:06 +00:00
Merge pull request #1075 from tahoe-lafs/3729.scripts-python-3-part-4
Finish porting allmydata.scripts to Python 3 Fixes ticket:3729
This commit is contained in:
commit
e2831ee8b4
0
newsfragments/3729.minor
Normal file
0
newsfragments/3729.minor
Normal file
@ -1,6 +1,14 @@
|
|||||||
|
"""
|
||||||
|
Ported to Python 3.
|
||||||
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from past.builtins import unicode
|
from future.utils import PY2
|
||||||
|
if PY2:
|
||||||
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
from urllib.parse import quote as url_quote
|
from urllib.parse import quote as url_quote
|
||||||
from allmydata.scripts.common_http import do_http, check_http_error
|
from allmydata.scripts.common_http import do_http, check_http_error
|
||||||
@ -37,7 +45,7 @@ def mkdir(options):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
# create a new directory at the given location
|
# create a new directory at the given location
|
||||||
path = unicode(path, "utf-8")
|
path = str(path, "utf-8")
|
||||||
if path.endswith("/"):
|
if path.endswith("/"):
|
||||||
path = path[:-1]
|
path = path[:-1]
|
||||||
# path must be "/".join([s.encode("utf-8") for s in segments])
|
# path must be "/".join([s.encode("utf-8") for s in segments])
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
|
"""
|
||||||
|
Ported to Python 3.
|
||||||
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from past.builtins import unicode
|
from future.utils import PY2
|
||||||
|
if PY2:
|
||||||
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from urllib.parse import quote as url_quote
|
from urllib.parse import quote as url_quote
|
||||||
@ -27,7 +35,7 @@ def mv(options, mode="move"):
|
|||||||
except UnknownAliasError as e:
|
except UnknownAliasError as e:
|
||||||
e.display(stderr)
|
e.display(stderr)
|
||||||
return 1
|
return 1
|
||||||
from_path = unicode(from_path, "utf-8")
|
from_path = str(from_path, "utf-8")
|
||||||
from_url = nodeurl + "uri/%s" % url_quote(rootcap)
|
from_url = nodeurl + "uri/%s" % url_quote(rootcap)
|
||||||
if from_path:
|
if from_path:
|
||||||
from_url += "/" + escape_path(from_path)
|
from_url += "/" + escape_path(from_path)
|
||||||
@ -47,7 +55,7 @@ def mv(options, mode="move"):
|
|||||||
e.display(stderr)
|
e.display(stderr)
|
||||||
return 1
|
return 1
|
||||||
to_url = nodeurl + "uri/%s" % url_quote(rootcap)
|
to_url = nodeurl + "uri/%s" % url_quote(rootcap)
|
||||||
path = unicode(path, "utf-8")
|
path = str(path, "utf-8")
|
||||||
if path:
|
if path:
|
||||||
to_url += "/" + escape_path(path)
|
to_url += "/" + escape_path(path)
|
||||||
|
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
|
"""
|
||||||
|
Ported to Python 3.
|
||||||
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from future.utils import PY2
|
from future.utils import PY2
|
||||||
from past.builtins import unicode
|
if PY2:
|
||||||
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from urllib.parse import quote as url_quote
|
from urllib.parse import quote as url_quote
|
||||||
@ -56,7 +63,7 @@ def put(options):
|
|||||||
except UnknownAliasError as e:
|
except UnknownAliasError as e:
|
||||||
e.display(stderr)
|
e.display(stderr)
|
||||||
return 1
|
return 1
|
||||||
path = unicode(path, "utf-8")
|
path = str(path, "utf-8")
|
||||||
if path.startswith("/"):
|
if path.startswith("/"):
|
||||||
suggestion = to_file.replace(u"/", u"", 1)
|
suggestion = to_file.replace(u"/", u"", 1)
|
||||||
print("Error: The remote filename must not start with a slash", file=stderr)
|
print("Error: The remote filename must not start with a slash", file=stderr)
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
|
"""
|
||||||
|
Ported to Python 3.
|
||||||
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from future.utils import PY2
|
||||||
|
if PY2:
|
||||||
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"RunOptions",
|
"RunOptions",
|
||||||
"run",
|
"run",
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
|
"""
|
||||||
|
Ported to Python 3.
|
||||||
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from future.builtins import chr
|
from future.utils import PY2
|
||||||
|
if PY2:
|
||||||
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from urllib.parse import urlencode, quote as url_quote
|
from urllib.parse import urlencode, quote as url_quote
|
||||||
@ -53,7 +61,7 @@ def _get_json_for_cap(options, cap):
|
|||||||
'uri/%s?t=json' % url_quote(cap),
|
'uri/%s?t=json' % url_quote(cap),
|
||||||
)
|
)
|
||||||
|
|
||||||
def pretty_progress(percent, size=10, ascii=False):
|
def pretty_progress(percent, size=10, output_ascii=False):
|
||||||
"""
|
"""
|
||||||
Displays a unicode or ascii based progress bar of a certain
|
Displays a unicode or ascii based progress bar of a certain
|
||||||
length. Should we just depend on a library instead?
|
length. Should we just depend on a library instead?
|
||||||
@ -64,7 +72,7 @@ def pretty_progress(percent, size=10, ascii=False):
|
|||||||
curr = int(percent / 100.0 * size)
|
curr = int(percent / 100.0 * size)
|
||||||
part = (percent / (100.0 / size)) - curr
|
part = (percent / (100.0 / size)) - curr
|
||||||
|
|
||||||
if ascii:
|
if output_ascii:
|
||||||
part = int(part * 4)
|
part = int(part * 4)
|
||||||
part = '.oO%'[part]
|
part = '.oO%'[part]
|
||||||
block_chr = '#'
|
block_chr = '#'
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
|
"""
|
||||||
|
Ported to Python 3.
|
||||||
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from future.utils import PY2
|
||||||
|
if PY2:
|
||||||
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
from urllib.parse import quote as url_quote
|
from urllib.parse import quote as url_quote
|
||||||
from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
|
from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
|
||||||
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
|
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
|
||||||
|
@ -1,4 +1,14 @@
|
|||||||
from past.builtins import unicode
|
"""
|
||||||
|
Ported to Python 3.
|
||||||
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from future.utils import PY2
|
||||||
|
if PY2:
|
||||||
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
from urllib.parse import quote as url_quote
|
from urllib.parse import quote as url_quote
|
||||||
|
|
||||||
@ -18,7 +28,7 @@ def webopen(options, opener=None):
|
|||||||
except UnknownAliasError as e:
|
except UnknownAliasError as e:
|
||||||
e.display(stderr)
|
e.display(stderr)
|
||||||
return 1
|
return 1
|
||||||
path = unicode(path, "utf-8")
|
path = str(path, "utf-8")
|
||||||
if path == '/':
|
if path == '/':
|
||||||
path = ''
|
path = ''
|
||||||
url = nodeurl + "uri/%s" % url_quote(rootcap)
|
url = nodeurl + "uri/%s" % url_quote(rootcap)
|
||||||
|
@ -60,30 +60,30 @@ class FakeStatus(object):
|
|||||||
class ProgressBar(unittest.TestCase):
|
class ProgressBar(unittest.TestCase):
|
||||||
|
|
||||||
def test_ascii0(self):
|
def test_ascii0(self):
|
||||||
prog = pretty_progress(80.0, size=10, ascii=True)
|
prog = pretty_progress(80.0, size=10, output_ascii=True)
|
||||||
self.assertEqual('########. ', prog)
|
self.assertEqual('########. ', prog)
|
||||||
|
|
||||||
def test_ascii1(self):
|
def test_ascii1(self):
|
||||||
prog = pretty_progress(10.0, size=10, ascii=True)
|
prog = pretty_progress(10.0, size=10, output_ascii=True)
|
||||||
self.assertEqual('#. ', prog)
|
self.assertEqual('#. ', prog)
|
||||||
|
|
||||||
def test_ascii2(self):
|
def test_ascii2(self):
|
||||||
prog = pretty_progress(13.0, size=10, ascii=True)
|
prog = pretty_progress(13.0, size=10, output_ascii=True)
|
||||||
self.assertEqual('#o ', prog)
|
self.assertEqual('#o ', prog)
|
||||||
|
|
||||||
def test_ascii3(self):
|
def test_ascii3(self):
|
||||||
prog = pretty_progress(90.0, size=10, ascii=True)
|
prog = pretty_progress(90.0, size=10, output_ascii=True)
|
||||||
self.assertEqual('#########.', prog)
|
self.assertEqual('#########.', prog)
|
||||||
|
|
||||||
def test_unicode0(self):
|
def test_unicode0(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
pretty_progress(82.0, size=10, ascii=False),
|
pretty_progress(82.0, size=10, output_ascii=False),
|
||||||
u'\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258e ',
|
u'\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258e ',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_unicode1(self):
|
def test_unicode1(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
pretty_progress(100.0, size=10, ascii=False),
|
pretty_progress(100.0, size=10, output_ascii=False),
|
||||||
u'\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588',
|
u'\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -110,6 +110,13 @@ PORTED_MODULES = [
|
|||||||
"allmydata.scripts.tahoe_invite",
|
"allmydata.scripts.tahoe_invite",
|
||||||
"allmydata.scripts.tahoe_ls",
|
"allmydata.scripts.tahoe_ls",
|
||||||
"allmydata.scripts.tahoe_manifest",
|
"allmydata.scripts.tahoe_manifest",
|
||||||
|
"allmydata.scripts.tahoe_mkdir",
|
||||||
|
"allmydata.scripts.tahoe_mv",
|
||||||
|
"allmydata.scripts.tahoe_put",
|
||||||
|
"allmydata.scripts.tahoe_run",
|
||||||
|
"allmydata.scripts.tahoe_status",
|
||||||
|
"allmydata.scripts.tahoe_unlink",
|
||||||
|
"allmydata.scripts.tahoe_webopen",
|
||||||
"allmydata.scripts.types_",
|
"allmydata.scripts.types_",
|
||||||
"allmydata.stats",
|
"allmydata.stats",
|
||||||
"allmydata.storage_client",
|
"allmydata.storage_client",
|
||||||
|
Loading…
Reference in New Issue
Block a user