##// END OF EJS Templates
py3: wrap tempfile.mkdtemp() to use bytes path...
Yuya Nishihara -
r38183:2ce60954 default
parent child Browse files
Show More
@@ -10,10 +10,11 import errno
10 import os
10 import os
11 import re
11 import re
12 import shutil
12 import shutil
13 import tempfile
13
14 from mercurial.i18n import _
14 from mercurial.i18n import _
15 from mercurial import (
15 from mercurial import (
16 error,
16 error,
17 pycompat,
17 util,
18 util,
18 )
19 )
19 from mercurial.utils import dateutil
20 from mercurial.utils import dateutil
@@ -76,7 +77,7 class darcs_source(common.converter_sour
76 self.ui.warn(_('failed to detect repository format!'))
77 self.ui.warn(_('failed to detect repository format!'))
77
78
78 def before(self):
79 def before(self):
79 self.tmppath = tempfile.mkdtemp(
80 self.tmppath = pycompat.mkdtemp(
80 prefix='convert-' + os.path.basename(self.path) + '-')
81 prefix='convert-' + os.path.basename(self.path) + '-')
81 output, status = self.run('init', repodir=self.tmppath)
82 output, status = self.run('init', repodir=self.tmppath)
82 self.checkexit(status)
83 self.checkexit(status)
@@ -71,7 +71,7 import os
71 import re
71 import re
72 import shutil
72 import shutil
73 import stat
73 import stat
74 import tempfile
74
75 from mercurial.i18n import _
75 from mercurial.i18n import _
76 from mercurial.node import (
76 from mercurial.node import (
77 nullid,
77 nullid,
@@ -210,7 +210,7 def dodiff(ui, repo, cmdline, pats, opts
210 if not common:
210 if not common:
211 return 0
211 return 0
212
212
213 tmproot = tempfile.mkdtemp(prefix='extdiff.')
213 tmproot = pycompat.mkdtemp(prefix='extdiff.')
214 try:
214 try:
215 if not opts.get('patch'):
215 if not opts.get('patch'):
216 # Always make a copy of node1a (and node1b, if applicable)
216 # Always make a copy of node1a (and node1b, if applicable)
@@ -87,7 +87,6 from __future__ import absolute_import
87
87
88 import os
88 import os
89 import re
89 import re
90 import tempfile
91 import weakref
90 import weakref
92
91
93 from mercurial.i18n import _
92 from mercurial.i18n import _
@@ -434,7 +433,7 def demo(ui, repo, *args, **opts):
434 ui.write('%s = %s\n' % (k, v))
433 ui.write('%s = %s\n' % (k, v))
435
434
436 fn = 'demo.txt'
435 fn = 'demo.txt'
437 tmpdir = tempfile.mkdtemp('', 'kwdemo.')
436 tmpdir = pycompat.mkdtemp('', 'kwdemo.')
438 ui.note(_('creating temporary repository at %s\n') % tmpdir)
437 ui.note(_('creating temporary repository at %s\n') % tmpdir)
439 if repo is None:
438 if repo is None:
440 baseui = ui
439 baseui = ui
@@ -79,7 +79,6 import email.utils as eutil
79 import errno
79 import errno
80 import os
80 import os
81 import socket
81 import socket
82 import tempfile
83
82
84 from mercurial.i18n import _
83 from mercurial.i18n import _
85 from mercurial import (
84 from mercurial import (
@@ -317,7 +316,7 def _getbundle(repo, dest, **opts):
317 The bundle is a returned as a single in-memory binary blob.
316 The bundle is a returned as a single in-memory binary blob.
318 """
317 """
319 ui = repo.ui
318 ui = repo.ui
320 tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
319 tmpdir = pycompat.mkdtemp(prefix='hg-email-bundle-')
321 tmpfn = os.path.join(tmpdir, 'bundle')
320 tmpfn = os.path.join(tmpdir, 'bundle')
322 btype = ui.config('patchbomb', 'bundletype')
321 btype = ui.config('patchbomb', 'bundletype')
323 if btype:
322 if btype:
@@ -15,7 +15,6 from __future__ import absolute_import
15
15
16 import os
16 import os
17 import shutil
17 import shutil
18 import tempfile
19
18
20 from .i18n import _
19 from .i18n import _
21 from .node import nullid
20 from .node import nullid
@@ -270,7 +269,7 class bundlerepository(localrepo.localre
270 try:
269 try:
271 localrepo.localrepository.__init__(self, ui, repopath)
270 localrepo.localrepository.__init__(self, ui, repopath)
272 except error.RepoError:
271 except error.RepoError:
273 self._tempparent = tempfile.mkdtemp()
272 self._tempparent = pycompat.mkdtemp()
274 localrepo.instance(ui, self._tempparent, 1)
273 localrepo.instance(ui, self._tempparent, 1)
275 localrepo.localrepository.__init__(self, ui, self._tempparent)
274 localrepo.localrepository.__init__(self, ui, self._tempparent)
276 self.ui.setconfig('phases', 'publish', False, 'bundlerepo')
275 self.ui.setconfig('phases', 'publish', False, 'bundlerepo')
@@ -11,7 +11,6 import contextlib
11 import os
11 import os
12 import re
12 import re
13 import shutil
13 import shutil
14 import tempfile
15
14
16 from .i18n import _
15 from .i18n import _
17 from .node import nullid, short
16 from .node import nullid, short
@@ -713,7 +712,7 def _maketempfiles(repo, fco, fca, local
713 tmproot = None
712 tmproot = None
714 tmprootprefix = repo.ui.config('experimental', 'mergetempdirprefix')
713 tmprootprefix = repo.ui.config('experimental', 'mergetempdirprefix')
715 if tmprootprefix:
714 if tmprootprefix:
716 tmproot = tempfile.mkdtemp(prefix=tmprootprefix)
715 tmproot = pycompat.mkdtemp(prefix=tmprootprefix)
717
716
718 def maketempfrompath(prefix, path):
717 def maketempfrompath(prefix, path):
719 fullbase, ext = os.path.splitext(path)
718 fullbase, ext = os.path.splitext(path)
@@ -18,7 +18,6 import os
18 import posixpath
18 import posixpath
19 import re
19 import re
20 import shutil
20 import shutil
21 import tempfile
22 import zlib
21 import zlib
23
22
24 from .i18n import _
23 from .i18n import _
@@ -573,7 +572,7 class filestore(object):
573 self.size += len(data)
572 self.size += len(data)
574 else:
573 else:
575 if self.opener is None:
574 if self.opener is None:
576 root = tempfile.mkdtemp(prefix='hg-patch-')
575 root = pycompat.mkdtemp(prefix='hg-patch-')
577 self.opener = vfsmod.vfs(root)
576 self.opener = vfsmod.vfs(root)
578 # Avoid filename issues with these simple names
577 # Avoid filename issues with these simple names
579 fn = '%d' % self.created
578 fn = '%d' % self.created
@@ -386,6 +386,9 def getoptb(args, shortlist, namelist):
386 def gnugetoptb(args, shortlist, namelist):
386 def gnugetoptb(args, shortlist, namelist):
387 return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)
387 return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)
388
388
389 def mkdtemp(suffix=b'', prefix=b'tmp', dir=None):
390 return tempfile.mkdtemp(suffix, prefix, dir)
391
389 # text=True is not supported; use util.from/tonativeeol() instead
392 # text=True is not supported; use util.from/tonativeeol() instead
390 def mkstemp(suffix=b'', prefix=b'tmp', dir=None):
393 def mkstemp(suffix=b'', prefix=b'tmp', dir=None):
391 return tempfile.mkstemp(suffix, prefix, dir)
394 return tempfile.mkstemp(suffix, prefix, dir)
@@ -8,7 +8,6
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import stat
10 import stat
11 import tempfile
12
11
13 from .i18n import _
12 from .i18n import _
14 from . import (
13 from . import (
@@ -18,6 +17,7 from . import (
18 hg,
17 hg,
19 localrepo,
18 localrepo,
20 manifest,
19 manifest,
20 pycompat,
21 revlog,
21 revlog,
22 scmutil,
22 scmutil,
23 util,
23 util,
@@ -657,7 +657,7 def _upgraderepo(ui, srcrepo, dstrepo, r
657
657
658 ui.write(_('data fully migrated to temporary repository\n'))
658 ui.write(_('data fully migrated to temporary repository\n'))
659
659
660 backuppath = tempfile.mkdtemp(prefix='upgradebackup.', dir=srcrepo.path)
660 backuppath = pycompat.mkdtemp(prefix='upgradebackup.', dir=srcrepo.path)
661 backupvfs = vfsmod.vfs(backuppath)
661 backupvfs = vfsmod.vfs(backuppath)
662
662
663 # Make a backup of requires file first, as it is the first to be modified.
663 # Make a backup of requires file first, as it is the first to be modified.
@@ -842,7 +842,7 def upgraderepo(ui, repo, run=False, opt
842 # data. There are less heavyweight ways to do this, but it is easier
842 # data. There are less heavyweight ways to do this, but it is easier
843 # to create a new repo object than to instantiate all the components
843 # to create a new repo object than to instantiate all the components
844 # (like the store) separately.
844 # (like the store) separately.
845 tmppath = tempfile.mkdtemp(prefix='upgrade.', dir=repo.path)
845 tmppath = pycompat.mkdtemp(prefix='upgrade.', dir=repo.path)
846 backuppath = None
846 backuppath = None
847 try:
847 try:
848 ui.write(_('creating temporary repository to stage migrated '
848 ui.write(_('creating temporary repository to stage migrated '
General Comments 0
You need to be logged in to leave comments. Login now