Beispiel #1
0
def get_tree_files(file_list):
  """
  Get a tree, and the file_ids from that tree, from the inputs.
  
  This returns the tree (a working tree or basis tree), a list of the
  file_ids belonging to that tree, and a list of remaining files (that
  presumably belong to another tree).
  """

  file_id_list = []
  try:
    (tree, rel_path) = workingtree.WorkingTree.open_containing(file_list[0])
    branch1 = tree.branch
    base_path = osutils.normpath(tree.id2abspath(tree.get_root_id()))
  except errors.NoWorkingTree:
    (branch1, rel_path) = branch.Branch.open_containing(file_list[0])
    tree = branch1.basis_tree()
    base_path = osutils.normpath(branch1.base)
  except errors.NotLocalUrl:
    (branch1, rel_path) = branch.Branch.open_containing(file_list[0])
    tree = branch1.basis_tree()
    base_path = None

  tree.lock_read()
  try:

    i = 0
    for file_name in file_list:
      try:
        if i > 0:
          if base_path:
            rpath = osutils.relpath(base_path, file_name)
          else:
            (branch2, rpath) = branch.Branch.open_containing(file_name)
            if branch2.base != branch1.base:
              raise errors.PathNotChild(file_name, branch1.base)
        else:
          rpath = rel_path
        file_id = tree.inventory.path2id(rpath)
        if file_id:
          file_id_list.append(file_id)
        else:
          if (not isinstance(transport.get_transport(file_name),
                             transport.local.LocalTransport)):
            raise errors.PathNotChild(file_name, branch1.base)
          else:
            raise errors.NotVersionedError(file_name)
        i += 1
      except errors.PathNotChild:
        break
        
  finally:
    tree.unlock()

  return (branch1, tree, file_id_list, file_list[i:len(file_list)])
Beispiel #2
0
    def _commit(self, date, author, patchname, changelog=None, entries=None,
                tags = [], isinitialcommit = False):
        """
        Commit the changeset.
        """
        from calendar import timegm  # like mktime(), but returns UTC timestamp
        from binascii import hexlify
        from re import search

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)
        if logmessage:
            self.log.info('Committing %r...', logmessage[0])
            logmessage = '\n'.join(logmessage)
        else:
            self.log.info('Committing...')
            logmessage = "Empty changelog"

        timestamp = timegm(date.utctimetuple())
        timezone  = date.utcoffset().seconds + date.utcoffset().days * 24 * 3600

        # Normalize file names
        if entries:
            entries = [normpath(entry) for entry in entries]

        self._working_tree.commit(logmessage, committer=author,
                                  specific_files=entries,
                                  verbose=self.repository.projectref().verbose,
                                  timestamp=timestamp, timezone=timezone)
Beispiel #3
0
    def _commit(self, date, author, patchname, changelog=None, entries=None,
                tags = [], isinitialcommit = False):
        """
        Commit the changeset.
        """
        from calendar import timegm  # like mktime(), but returns UTC timestamp
        from binascii import hexlify
        from re import search

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)
        if logmessage:
            self.log.info('Committing %s...', logmessage[0])
            logmessage = '\n'.join(logmessage)
        else:
            self.log.info('Committing...')
            logmessage = "Empty changelog"

        timestamp = timegm(date.utctimetuple())
        timezone  = date.utcoffset().seconds + date.utcoffset().days * 24 * 3600

        # Normalize file names
        if entries:
            entries = [normpath(entry) for entry in entries]

        self._working_tree.commit(logmessage, committer=author,
                                  specific_files=entries,
                                  verbose=self.repository.projectref().verbose,
                                  timestamp=timestamp, timezone=timezone)
Beispiel #4
0
def show_version(show_config=True, show_copyright=True, to_file=None):
    if to_file is None:
        to_file = sys.stdout
    to_file.write("Bazaar (bzr) %s\n" % bzrlib.__version__)
    # is bzrlib itself in a branch?
    src_tree = _get_bzr_source_tree()
    if src_tree:
        src_revision_id = src_tree.last_revision()
        revno = src_tree.branch.revision_id_to_revno(src_revision_id)
        to_file.write("  from bzr checkout %s\n" % (src_tree.basedir,))
        to_file.write("    revision: %s\n" % (revno,))
        to_file.write("    revid: %s\n" % (src_revision_id,))
        to_file.write("    branch nick: %s\n" % (src_tree.branch.nick,))

    to_file.write("  Python interpreter: ")
    # show path to python interpreter
    # (bzr.exe use python interpreter from pythonXY.dll
    # but sys.executable point to bzr.exe itself)
    # however, sys.frozen exists if running from bzr.exe
    # see http://www.py2exe.org/index.cgi/Py2exeEnvironment
    if getattr(sys, 'frozen', None) is None: # if not bzr.exe
        to_file.write(sys.executable + ' ')
    else:
        # pythonXY.dll
        basedir = os.path.dirname(sys.executable)
        python_dll = "python%d%d.dll" % sys.version_info[:2]
        to_file.write(os.path.join(basedir, python_dll) + ' ')
    # and now version of python interpreter
    to_file.write(bzrlib._format_version_tuple(sys.version_info))
    to_file.write('\n')

    to_file.write("  Python standard library:" + ' ')
    to_file.write(os.path.dirname(os.__file__) + '\n')
    to_file.write("  Platform: %s\n"
                  % platform.platform(aliased=1).decode('utf-8'))
    to_file.write("  bzrlib: ")
    if len(bzrlib.__path__) > 1:
        # print repr, which is a good enough way of making it clear it's
        # more than one element (eg ['/foo/bar', '/foo/bzr'])
        to_file.write(repr(bzrlib.__path__) + '\n')
    else:
        to_file.write(bzrlib.__path__[0] + '\n')
    if show_config:
        config_dir = osutils.normpath(config.config_dir())  # use native slashes
        if not isinstance(config_dir, unicode):
            config_dir = config_dir.decode(osutils.get_user_encoding())
        to_file.write("  Bazaar configuration: %s\n" % (config_dir,))
        to_file.write("  Bazaar log file: ")
        to_file.write(trace._bzr_log_filename + '\n')
    if show_copyright:
        to_file.write('\n')
        to_file.write(bzrlib.__copyright__ + '\n')
        to_file.write("http://bazaar.canonical.com/\n")
        to_file.write('\n')
        to_file.write("bzr comes with ABSOLUTELY NO WARRANTY.  bzr is free software, and\n")
        to_file.write("you may use, modify and redistribute it under the terms of the GNU\n")
        to_file.write("General Public License version 2 or later.\n")
        to_file.write("\nBazaar is part of the GNU Project to produce a free operating "
                "system.\n")
    to_file.write('\n')
Beispiel #5
0
 def test_plugin_get_path_py_not_pyc(self):
     self.setup_plugin()         # after first import there will be plugin.pyc
     self.teardown_plugin()
     bzrlib.plugin.load_from_path(['.']) # import plugin.pyc
     plugins = bzrlib.plugin.plugins()
     plugin = plugins['plugin']
     plugin_path = self.test_dir + '/plugin.py'
     self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
 def test_plugin_get_path_py_not_pyc(self):
     # first import creates plugin.pyc
     self.setup_plugin()
     self.teardown_plugin()
     plugin.load_from_path(['.'])  # import plugin.pyc
     p = plugin.plugins()['plugin']
     plugin_path = self.test_dir + '/plugin.py'
     self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
Beispiel #7
0
 def test_plugin_get_path_py_not_pyc(self):
     # first import creates plugin.pyc
     self.setup_plugin()
     self.teardown_plugin()
     plugin.load_from_path(['.']) # import plugin.pyc
     p = plugin.plugins()['plugin']
     plugin_path = self.test_dir + '/plugin.py'
     self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
 def test_plugin_get_path_pyc_only(self):
     # first import creates plugin.pyc (or plugin.pyo depending on __debug__)
     self.setup_plugin()
     self.teardown_plugin()
     os.unlink(self.test_dir + '/plugin.py')
     plugin.load_from_path(['.'])  # import plugin.pyc (or .pyo)
     p = plugin.plugins()['plugin']
     if __debug__:
         plugin_path = self.test_dir + '/plugin.pyc'
     else:
         plugin_path = self.test_dir + '/plugin.pyo'
     self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
Beispiel #9
0
 def test_plugin_get_path_pyc_only(self):
     self.setup_plugin()         # after first import there will be plugin.pyc
     self.teardown_plugin()
     os.unlink(self.test_dir + '/plugin.py')
     bzrlib.plugin.load_from_path(['.']) # import plugin.pyc
     plugins = bzrlib.plugin.plugins()
     plugin = plugins['plugin']
     if __debug__:
         plugin_path = self.test_dir + '/plugin.pyc'
     else:
         plugin_path = self.test_dir + '/plugin.pyo'
     self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
Beispiel #10
0
 def test_plugin_get_path_pyc_only(self):
     # first import creates plugin.pyc (or plugin.pyo depending on __debug__)
     self.setup_plugin()
     self.teardown_plugin()
     os.unlink(self.test_dir + '/plugin.py')
     plugin.load_from_path(['.']) # import plugin.pyc (or .pyo)
     p = plugin.plugins()['plugin']
     if __debug__:
         plugin_path = self.test_dir + '/plugin.pyc'
     else:
         plugin_path = self.test_dir + '/plugin.pyo'
     self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
Beispiel #11
0
 def _probe(self):
     fileno, name = tempfile.mkstemp(prefix='MixedCase')
     try:
         # first check truly case-preserving for created files, then check
         # case insensitive when opening existing files.
         name = osutils.normpath(name)
         base, rel = osutils.split(name)
         found_rel = osutils.canonical_relpath(base, name)
         return (found_rel == rel
                 and os.path.isfile(name.upper())
                 and os.path.isfile(name.lower()))
     finally:
         os.close(fileno)
         os.remove(name)
Beispiel #12
0
    def abspath(self, relpath):
        """Return the full url to the given relative URL."""
        # TODO: url escape the result. RBC 20060523.
        # jam 20060426 Using normpath on the real path, because that ensures
        #       proper handling of stuff like
        relpath = self._anvilise_path(relpath)
        path = osutils.normpath(osutils.pathjoin(
                    self._local_base, urlutils.unescape(relpath)))
        # on windows, our _local_base may or may not have a drive specified
        # (ie, it may be "/" or "c:/foo").
        # If 'relpath' is '/' we *always* get back an abspath without
        # the drive letter - but if our transport already has a drive letter,
        # we want our abspaths to have a drive letter too - so handle that
        # here.
        if (sys.platform == "win32" and self._local_base[1:2] == ":"
            and path == '/'):
            path = self._local_base[:3]

        return urlutils.local_path_to_url(path)
 def start_server(self, backing_server=None):
     # XXX: TODO: make sftpserver back onto backing_server rather than local
     # disk.
     if not (backing_server is None
             or isinstance(backing_server, test_server.LocalURLServer)):
         raise AssertionError(
             'backing_server should not be %r, because this can only serve '
             'the local current working directory.' % (backing_server, ))
     self._original_vendor = ssh._ssh_vendor_manager._cached_ssh_vendor
     ssh._ssh_vendor_manager._cached_ssh_vendor = self._vendor
     if sys.platform == 'win32':
         # Win32 needs to use the UNICODE api
         self._homedir = os.getcwdu()
         # Normalize the path or it will be wrongly escaped
         self._homedir = osutils.normpath(self._homedir)
     else:
         # But unix SFTP servers should just deal in bytestreams
         self._homedir = os.getcwd()
     if self._server_homedir is None:
         self._server_homedir = self._homedir
     self._root = '/'
     if sys.platform == 'win32':
         self._root = ''
     super(SFTPServer, self).start_server()
Beispiel #14
0
 def start_server(self, backing_server=None):
     # XXX: TODO: make sftpserver back onto backing_server rather than local
     # disk.
     if not (backing_server is None or
             isinstance(backing_server, test_server.LocalURLServer)):
         raise AssertionError(
             'backing_server should not be %r, because this can only serve '
             'the local current working directory.' % (backing_server,))
     self._original_vendor = ssh._ssh_vendor_manager._cached_ssh_vendor
     ssh._ssh_vendor_manager._cached_ssh_vendor = self._vendor
     if sys.platform == 'win32':
         # Win32 needs to use the UNICODE api
         self._homedir = os.getcwdu()
         # Normalize the path or it will be wrongly escaped
         self._homedir = osutils.normpath(self._homedir)
     else:
         # But unix SFTP servers should just deal in bytestreams
         self._homedir = os.getcwd()
     if self._server_homedir is None:
         self._server_homedir = self._homedir
     self._root = '/'
     if sys.platform == 'win32':
         self._root = ''
     super(SFTPServer, self).start_server()
 def canonicalize(self, path):
     if os.path.isabs(path):
         return osutils.normpath(path)
     else:
         return osutils.normpath('/' + os.path.join(self.home, path))
Beispiel #16
0
 def test_trivial_plugin_get_path(self):
     self.setup_plugin()
     plugins = bzrlib.plugin.plugins()
     plugin = plugins['plugin']
     plugin_path = self.test_dir + '/plugin.py'
     self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
Beispiel #17
0
 def canonicalize(self, path):
     if os.path.isabs(path):
         return osutils.normpath(path)
     else:
         return osutils.normpath('/' + os.path.join(self.home, path))
 def test_trivial_plugin_get_path(self):
     self.setup_plugin()
     p = plugin.plugins()['plugin']
     plugin_path = self.test_dir + '/plugin.py'
     self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
Beispiel #19
0
 def test_trivial_plugin_get_path(self):
     self.setup_plugin()
     p = plugin.plugins()['plugin']
     plugin_path = self.test_dir + '/plugin.py'
     self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
Beispiel #20
0
def show_version(show_config=True, show_copyright=True, to_file=None):
    if to_file is None:
        to_file = sys.stdout
    to_file.write("Bazaar (bzr) %s\n" % bzrlib.__version__)
    # is bzrlib itself in a branch?
    src_tree = _get_bzr_source_tree()
    if src_tree:
        src_revision_id = src_tree.last_revision()
        revno = src_tree.branch.revision_id_to_revno(src_revision_id)
        to_file.write("  from bzr checkout %s\n" % (src_tree.basedir, ))
        to_file.write("    revision: %s\n" % (revno, ))
        to_file.write("    revid: %s\n" % (src_revision_id, ))
        to_file.write("    branch nick: %s\n" % (src_tree.branch.nick, ))

    to_file.write("  Python interpreter: ")
    # show path to python interpreter
    # (bzr.exe use python interpreter from pythonXY.dll
    # but sys.executable point to bzr.exe itself)
    # however, sys.frozen exists if running from bzr.exe
    # see http://www.py2exe.org/index.cgi/Py2exeEnvironment
    if getattr(sys, 'frozen', None) is None:  # if not bzr.exe
        to_file.write(sys.executable + ' ')
    else:
        # pythonXY.dll
        basedir = os.path.dirname(sys.executable)
        python_dll = "python%d%d.dll" % sys.version_info[:2]
        to_file.write(os.path.join(basedir, python_dll) + ' ')
    # and now version of python interpreter
    to_file.write(bzrlib._format_version_tuple(sys.version_info))
    to_file.write('\n')

    to_file.write("  Python standard library:" + ' ')
    to_file.write(os.path.dirname(os.__file__) + '\n')
    to_file.write("  Platform: %s\n" %
                  platform.platform(aliased=1).decode('utf-8'))
    to_file.write("  bzrlib: ")
    if len(bzrlib.__path__) > 1:
        # print repr, which is a good enough way of making it clear it's
        # more than one element (eg ['/foo/bar', '/foo/bzr'])
        to_file.write(repr(bzrlib.__path__) + '\n')
    else:
        to_file.write(bzrlib.__path__[0] + '\n')
    if show_config:
        config_dir = osutils.normpath(
            config.config_dir())  # use native slashes
        if not isinstance(config_dir, unicode):
            config_dir = config_dir.decode(osutils.get_user_encoding())
        to_file.write("  Bazaar configuration: %s\n" % (config_dir, ))
        to_file.write("  Bazaar log file: ")
        to_file.write(trace._bzr_log_filename + '\n')
    if show_copyright:
        to_file.write('\n')
        to_file.write(bzrlib.__copyright__ + '\n')
        to_file.write("http://bazaar.canonical.com/\n")
        to_file.write('\n')
        to_file.write(
            "bzr comes with ABSOLUTELY NO WARRANTY.  bzr is free software, and\n"
        )
        to_file.write(
            "you may use, modify and redistribute it under the terms of the GNU\n"
        )
        to_file.write("General Public License version 2 or later.\n")
        to_file.write(
            "\nBazaar is part of the GNU Project to produce a free operating "
            "system.\n")
    to_file.write('\n')