Commit 66be4f8a authored by Matthias Putz's avatar Matthias Putz

migrated to py33, init works so far (bug in links)

parent 2acbeb81
......@@ -79,7 +79,7 @@ class _GitCall(object):
def version(self):
p = GitCommand(None, ['--version'], capture_stdout=True)
if p.Wait() == 0:
return p.stdout
return str(p.stdout, encoding='UTF-8')
return None
def version_tuple(self):
......@@ -117,7 +117,7 @@ def git_require(min_version, fail=False):
return False
def _setenv(env, name, value):
env[name] = value.encode()
env[name] = value.encode(encoding='UTF-8')
class GitCommand(object):
def __init__(self,
......@@ -164,7 +164,7 @@ class GitCommand(object):
command = [GIT]
if bare:
if gitdir:
_setenv(env, GIT_DIR, gitdir)
env[GIT_DIR] = gitdir
cwd = None
command.extend(cmdv)
......
......@@ -14,7 +14,7 @@
# limitations under the License.
from __future__ import print_function
import cPickle
import pickle
import os
import re
import subprocess
......@@ -262,7 +262,7 @@ class GitConfig(object):
Trace(': unpickle %s', self.file)
fd = open(self._pickle, 'rb')
try:
return cPickle.load(fd)
return pickle.load(fd)
finally:
fd.close()
except EOFError:
......@@ -271,7 +271,7 @@ class GitConfig(object):
except IOError:
os.remove(self._pickle)
return None
except cPickle.PickleError:
except pickle.PickleError:
os.remove(self._pickle)
return None
......@@ -279,13 +279,13 @@ class GitConfig(object):
try:
fd = open(self._pickle, 'wb')
try:
cPickle.dump(cache, fd, cPickle.HIGHEST_PROTOCOL)
pickle.dump(cache, fd, pickle.HIGHEST_PROTOCOL)
finally:
fd.close()
except IOError:
if os.path.exists(self._pickle):
os.remove(self._pickle)
except cPickle.PickleError:
except pickle.PickleError:
if os.path.exists(self._pickle):
os.remove(self._pickle)
......@@ -324,7 +324,7 @@ class GitConfig(object):
capture_stdout = True,
capture_stderr = True)
if p.Wait() == 0:
return p.stdout
return str(p.stdout, encoding='UTF-8')
else:
GitError('git config %s: %s' % (str(args), p.stderr))
......@@ -701,7 +701,7 @@ class Branch(object):
self._Set('merge', self.merge)
else:
fd = open(self._config.file, 'ab')
fd = open(self._config.file, 'at')
try:
fd.write('[branch "%s"]\n' % self.name)
if self.remote:
......
......@@ -66,7 +66,7 @@ class GitRefs(object):
def _NeedUpdate(self):
Trace(': scan refs %s', self._gitdir)
for name, mtime in self._mtime.iteritems():
for name, mtime in self._mtime.items():
try:
if mtime != os.path.getmtime(os.path.join(self._gitdir, name)):
return True
......@@ -89,7 +89,7 @@ class GitRefs(object):
attempts = 0
while scan and attempts < 5:
scan_next = {}
for name, dest in scan.iteritems():
for name, dest in scan.items():
if dest in self._phyref:
self._phyref[name] = self._phyref[dest]
else:
......@@ -100,7 +100,7 @@ class GitRefs(object):
def _ReadPackedRefs(self):
path = os.path.join(self._gitdir, 'packed-refs')
try:
fd = open(path, 'rb')
fd = open(path, 'rt')
mtime = os.path.getmtime(path)
except IOError:
return
......@@ -137,7 +137,7 @@ class GitRefs(object):
def _ReadLoose1(self, path, name):
try:
fd = open(path, 'rb')
fd = open(path, 'rt')
except IOError:
return
......
......@@ -50,6 +50,17 @@ from pager import RunPager
from subcmds import all_commands
REMOTE_DBG = True
if REMOTE_DBG:
try:
sys.path.append("C:\Program Files\eclipsePython\plugins\org.python.pydev_2.7.1.2012100913\pysrc")
import pydevd as pydevd
# stdoutToServer and stderrToServer redirect stdout and stderr to eclipse console
pydevd.settrace('localhost', stdoutToServer=True, stderrToServer=True)
except ImportError:
sys.stderr.write("Error: you must add pydevd in a pysrc folder (e.g. in eclipse plugin) to your PYTHONPATH.")
sys.exit(1)
global_options = optparse.OptionParser(
usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]"
)
......
......@@ -18,8 +18,9 @@ import itertools
import os
import re
import sys
import urlparse
import urllib
import xml.dom.minidom
import xml.parsers.expat
from git_config import GitConfig
from git_refs import R_HEADS, HEAD
......@@ -30,8 +31,8 @@ MANIFEST_FILE_NAME = 'manifest.xml'
LOCAL_MANIFEST_NAME = 'local_manifest.xml'
LOCAL_MANIFESTS_DIR_NAME = 'local_manifests'
urlparse.uses_relative.extend(['ssh', 'git'])
urlparse.uses_netloc.extend(['ssh', 'git'])
urllib.parse.uses_relative.extend(['ssh', 'git'])
urllib.parse.uses_netloc.extend(['ssh', 'git'])
class _Default(object):
"""Project defaults within the manifest."""
......@@ -73,7 +74,7 @@ class _XmlRemote(object):
# ie, if manifestUrl is of the form <hostname:port>
if manifestUrl.find(':') != manifestUrl.find('/') - 1:
manifestUrl = 'gopher://' + manifestUrl
url = urlparse.urljoin(manifestUrl, url)
url = urllib.parse.urljoin(manifestUrl, url)
url = re.sub(r'^gopher://', '', url)
if p:
url = 'persistent-' + url
......@@ -388,9 +389,9 @@ class XmlManifest(object):
name = self._reqatt(node, 'name')
fp = os.path.join(include_root, name)
if not os.path.isfile(fp):
raise ManifestParseError, \
raise ManifestParseError(\
"include %s doesn't exist or isn't a file" % \
(name,)
(name,))
try:
nodes.extend(self._ParseManifestXml(fp, include_root))
# should isolate this to the exact exception, but that's
......@@ -496,7 +497,7 @@ class XmlManifest(object):
name = None
m_url = m.GetRemote(m.remote.name).url
if m_url.endswith('/.git'):
raise ManifestParseError, 'refusing to mirror %s' % m_url
raise ManifestParseError('refusing to mirror %s' % m_url)
if self._default and self._default.remote:
url = self._default.remote.resolvedFetchUrl
......@@ -590,7 +591,7 @@ class XmlManifest(object):
# Figure out minimum indentation, skipping the first line (the same line
# as the <notice> tag)...
minIndent = sys.maxint
minIndent = sys.maxsize
lines = notice.splitlines()
for line in lines[1:]:
lstrippedLine = line.lstrip()
......@@ -629,25 +630,25 @@ class XmlManifest(object):
if remote is None:
remote = self._default.remote
if remote is None:
raise ManifestParseError, \
raise ManifestParseError(\
"no remote for project %s within %s" % \
(name, self.manifestFile)
(name, self.manifestFile))
revisionExpr = node.getAttribute('revision')
if not revisionExpr:
revisionExpr = self._default.revisionExpr
if not revisionExpr:
raise ManifestParseError, \
raise ManifestParseError(\
"no revision for project %s within %s" % \
(name, self.manifestFile)
(name, self.manifestFile))
path = node.getAttribute('path')
if not path:
path = name
if path.startswith('/'):
raise ManifestParseError, \
raise ManifestParseError(\
"project %s path cannot be absolute in %s" % \
(name, self.manifestFile)
(name, self.manifestFile))
rebase = node.getAttribute('rebase')
if not rebase:
......@@ -751,7 +752,7 @@ class XmlManifest(object):
except ManifestParseError:
keep = "true"
if keep != "true" and keep != "false":
raise ManifestParseError, "optional \"keep\" attribute must be \"true\" or \"false\""
raise ManifestParseError("optional \"keep\" attribute must be \"true\" or \"false\"")
project.AddAnnotation(name, value, keep)
def _get_remote(self, node):
......@@ -761,9 +762,9 @@ class XmlManifest(object):
v = self._remotes.get(name)
if not v:
raise ManifestParseError, \
raise ManifestParseError(\
"remote %s not defined in %s" % \
(name, self.manifestFile)
(name, self.manifestFile))
return v
def _reqatt(self, node, attname):
......@@ -772,7 +773,7 @@ class XmlManifest(object):
"""
v = node.getAttribute(attname)
if not v:
raise ManifestParseError, \
raise ManifestParseError(\
"no %s in <%s> within %s" % \
(attname, node.nodeName, self.manifestFile)
(attname, node.nodeName, self.manifestFile))
return v
......@@ -39,14 +39,14 @@ from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
def _lwrite(path, content):
lock = '%s.lock' % path
fd = open(lock, 'wb')
fd = open(lock, 'wt')
try:
fd.write(content)
finally:
fd.close()
try:
os.rename(lock, path)
os.replace(lock, path)
except OSError:
os.remove(lock)
raise
......@@ -644,7 +644,7 @@ class Project(object):
all_refs = self._allrefs
heads = {}
for name, ref_id in all_refs.iteritems():
for name, ref_id in all_refs.items():
if name.startswith(R_HEADS):
name = name[len(R_HEADS):]
b = self.GetBranch(name)
......@@ -653,7 +653,7 @@ class Project(object):
b.revision = ref_id
heads[name] = b
for name, ref_id in all_refs.iteritems():
for name, ref_id in all_refs.items():
if name.startswith(R_PUB):
name = name[len(R_PUB):]
b = heads.get(name)
......@@ -849,13 +849,13 @@ class Project(object):
all_refs = self._allrefs
heads = set()
canrm = {}
for name, ref_id in all_refs.iteritems():
for name, ref_id in all_refs.items():
if name.startswith(R_HEADS):
heads.add(name)
elif name.startswith(R_PUB):
canrm[name] = ref_id
for name, ref_id in canrm.iteritems():
for name, ref_id in canrm.items():
n = name[len(R_PUB):]
if R_HEADS + n not in heads:
self.bare_git.DeleteRef(name, ref_id)
......@@ -866,14 +866,14 @@ class Project(object):
heads = {}
pubed = {}
for name, ref_id in self._allrefs.iteritems():
for name, ref_id in self._allrefs.items():
if name.startswith(R_HEADS):
heads[name[len(R_HEADS):]] = ref_id
elif name.startswith(R_PUB):
pubed[name[len(R_PUB):]] = ref_id
ready = []
for branch, ref_id in heads.iteritems():
for branch, ref_id in heads.items():
if branch in pubed and pubed[branch] == ref_id:
continue
if selected_branch and branch != selected_branch:
......@@ -1597,7 +1597,7 @@ class Project(object):
ids = set(all_refs.values())
tmp = set()
for r, ref_id in GitRefs(ref_dir).all.iteritems():
for r, ref_id in GitRefs(ref_dir).all.items():
if r not in all_refs:
if r.startswith(R_TAGS) or remote.WritesTo(r):
all_refs[r] = ref_id
......@@ -2074,7 +2074,7 @@ class Project(object):
else:
path = os.path.join(self._project.worktree, '.git', HEAD)
try:
fd = open(path, 'rb')
fd = open(path, 'rt')
except IOError:
raise NoManifestException(path)
try:
......@@ -2174,7 +2174,7 @@ class Project(object):
if not git_require((1, 7, 2)):
raise ValueError('cannot set config on command line for %s()'
% name)
for k, v in config.iteritems():
for k, v in config.items():
cmdv.append('-c')
cmdv.append('%s=%s' % (k, v))
cmdv.append(name)
......@@ -2189,7 +2189,7 @@ class Project(object):
self._project.name,
name,
p.stderr))
r = p.stdout
r = str(p.stdout, encoding='UTF-8')
if r.endswith('\n') and r.index('\n') == len(r) - 1:
return r[:-1]
return r
......
......@@ -38,8 +38,8 @@ for py in os.listdir(my_dir):
try:
cmd = getattr(mod, clsn)()
except AttributeError:
raise SyntaxError, '%s/%s does not define class %s' % (
__name__, py, clsn)
raise SyntaxError('%s/%s does not define class %s' % (
__name__, py, clsn))
name = name.replace('_', '-')
cmd.NAME = name
......
......@@ -98,7 +98,7 @@ is shown, then the branch appears in all projects.
project_cnt = len(projects)
for project in projects:
for name, b in project.GetBranches().iteritems():
for name, b in project.GetBranches().items():
b.project = project
if name not in all_branches:
all_branches[name] = BranchInfo(name)
......
......@@ -55,7 +55,7 @@ change id will be added.
if p.Wait() != 0:
print("error: Failed to retrieve old commit message", file=sys.stderr)
sys.exit(1)
old_msg = self._StripHeader(p.stdout)
old_msg = self._StripHeader(str(p.stdout, encoding='UTF-8'))
p = GitCommand(None,
['cherry-pick', sha1],
......
......@@ -14,7 +14,7 @@
# limitations under the License.
from __future__ import print_function
import fcntl
#import fcntl
import re
import os
import select
......@@ -218,47 +218,47 @@ without iterating through the remaining projects.
def fileno(self):
return self.fd.fileno()
empty = True
errbuf = ''
p.stdin.close()
s_in = [sfd(p.stdout, sys.stdout),
sfd(p.stderr, sys.stderr)]
for s in s_in:
flags = fcntl.fcntl(s.fd, fcntl.F_GETFL)
fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
while s_in:
in_ready, _out_ready, _err_ready = select.select(s_in, [], [])
for s in in_ready:
buf = s.fd.read(4096)
if not buf:
s.fd.close()
s_in.remove(s)
continue
if not opt.verbose:
if s.fd != p.stdout:
errbuf += buf
continue
if empty:
if first:
first = False
else:
out.nl()
out.project('project %s/', project.relpath)
out.nl()
out.flush()
if errbuf:
sys.stderr.write(errbuf)
sys.stderr.flush()
errbuf = ''
empty = False
s.dest.write(buf)
s.dest.flush()
# empty = True
# errbuf = ''
#
# p.stdin.close()
# s_in = [sfd(p.stdout, sys.stdout),
# sfd(p.stderr, sys.stderr)]
#
# for s in s_in:
# flags = fcntl.fcntl(s.fd, fcntl.F_GETFL)
# fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
#
# while s_in:
# in_ready, _out_ready, _err_ready = select.select(s_in, [], [])
# for s in in_ready:
# buf = s.fd.read(4096)
# if not buf:
# s.fd.close()
# s_in.remove(s)
# continue
#
# if not opt.verbose:
# if s.fd != p.stdout:
# errbuf += buf
# continue
#
# if empty:
# if first:
# first = False
# else:
# out.nl()
# out.project('project %s/', project.relpath)
# out.nl()
# out.flush()
# if errbuf:
# sys.stderr.write(errbuf)
# sys.stderr.flush()
# errbuf = ''
# empty = False
#
# s.dest.write(buf)
# s.dest.flush()
r = p.wait()
if r != 0:
......
......@@ -210,7 +210,7 @@ contain a line that matches both expressions:
# We cut the last element, to avoid a blank line.
#
r = p.stdout.split('\n')
r = str(p.stdout, encoding='UTF-8').split('\n')
r = r[0:-1]
if have_rev and full_name:
......
#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
from optparse import SUPPRESS_HELP
import sys
from command import Command, MirrorSafeCommand
from subcmds.sync import _PostRepoUpgrade
from subcmds.sync import _PostRepoFetch
class Selfupdate(Command, MirrorSafeCommand):
common = False
helpSummary = "Update repo to the latest version"
helpUsage = """
%prog
"""
helpDescription = """
The '%prog' command upgrades repo to the latest version, if a
newer version is available.
Normally this is done automatically by 'repo sync' and does not
need to be performed by an end-user.
"""
def _Options(self, p):
g = p.add_option_group('repo Version options')
g.add_option('--no-repo-verify',
dest='no_repo_verify', action='store_true',
help='do not verify repo source code')
g.add_option('--repo-upgraded',
dest='repo_upgraded', action='store_true',
help=SUPPRESS_HELP)
def Execute(self, opt, args):
rp = self.manifest.repoProject
rp.PreSync()
if opt.repo_upgraded:
_PostRepoUpgrade(self.manifest)
else:
if not rp.Sync_NetworkHalf():
print("error: can't update repo", file=sys.stderr)
sys.exit(1)
rp.bare_git.gc('--auto')
_PostRepoFetch(rp,
no_repo_verify = opt.no_repo_verify,
verbose = True)
......@@ -15,16 +15,16 @@
from command import PagedCommand
try:
import threading as _threading
except ImportError:
import dummy_threading as _threading
#try:
import threading as _threading
#except ImportError:
# import dummy_threading as _threading
import glob
import itertools
import os
import sys
import StringIO
import io
from color import Coloring
......@@ -142,7 +142,7 @@ the following meanings:
for project in all_projects:
sem.acquire()
class BufList(StringIO.StringIO):
class BufList(io.StringIO.StringIO):
def dump(self, ostream):
for entry in self.buflist:
ostream.write(entry)
......@@ -182,7 +182,7 @@ the following meanings:
try:
os.chdir(self.manifest.topdir)
outstring = StringIO.StringIO()
outstring = io.StringIO.StringIO()
self._FindOrphans(glob.glob('.*') + \
glob.glob('*'), \
proj_dirs, proj_dirs_parents, outstring)
......
......@@ -24,13 +24,13 @@ import socket
import subprocess
import sys
import time
import urlparse
import xmlrpclib
import urllib
import xmlrpc
try:
import threading as _threading
except ImportError:
import dummy_threading as _threading
#try:
import threading as _threading
#except ImportError:
# import dummy_threading as _threading
try:
import resource
......@@ -282,6 +282,8 @@ later is required to fix a server side protocol bug.
else:
sys.exit(1)
else:
# TODO
# assume jobs=1 always
threads = set()
lock = _threading.Lock()
sem = _threading.Semaphore(self.jobs)
......@@ -481,7 +483,7 @@ later is required to fix a server side protocol bug.
file=sys.stderr)
else:
try:
parse_result = urlparse.urlparse(manifest_server)
parse_result = urllib.parse(manifest_server)
if parse_result.hostname:
username, _account, password = \
info.authenticators(parse_result.hostname)
......@@ -499,7 +501,7 @@ later is required to fix a server side protocol bug.
1)
try:
server = xmlrpclib.Server(manifest_server)
server = xmlrpc.server(manifest_server)
if opt.smart_sync:
p = self.manifest.manifestProject
b = p.GetBranch(p.CurrentBranch)
......@@ -537,11 +539,11 @@ later is required to fix a server side protocol bug.
else:
print('error: %s' % manifest_str, file=sys.stderr)
sys.exit(1)
except (socket.error, IOError, xmlrpclib.Fault) as e:
except (socket.error, IOError, xmlrpc.client.Fault) as e:
print('error: cannot connect to manifest server %s:\n%s'
% (self.manifest.manifest_server, e), file=sys.stderr)
sys.exit(1)
except xmlrpclib.ProtocolError as e:
except xmlrpc.client.ProtocolError as e:
print('error: cannot connect to manifest server %s:\n%d %s'
% (self.manifest.manifest_server, e.errcode, e.errmsg),
file=sys.stderr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment