Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1007045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:33:26+00:00 2026-05-16T08:33:26+00:00

For example, say I moved a file from /project/file.cs to /project/subdir/file.cs . It would

  • 0

For example, say I moved a file from /project/file.cs to /project/subdir/file.cs. It would be nice if nautilus automatically converted this to bzr mv /project/file.cs /project/subdir/file.cs. Is it possible to set this up?

It would also be nice if I was warned when doing a plain old mv on version controlled files, but I suppose that’s a separate question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:33:27+00:00Added an answer on May 16, 2026 at 8:33 am

    Like you already indicated yourself you basically need something that listens for moves, so I thought I’d code something up that would give you an indication of how this would work.

    I tried using gio.FileMonitor but eventually went back to using plain old pyinotify because the latter has built-in support for detecting file renames/moves.

    import pyinotify
    
    import bzrlib
    from bzrlib.workingtree import WorkingTree
    from bzrlib.errors import NotBranchError, BzrRenameFailedError
    
    directories_to_watch = [
        # Add the paths to your working copies / branches to watch here
    ]
    
    wm = pyinotify.WatchManager()
    
    # When you listen to both MOVED_FROM and MOVED_TO the event for MOVED_TO will include both 
    # pathname (new path) and src_pathname (previous path).
    mask = pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO
    
    class EventHandler(pyinotify.ProcessEvent):
    
        def process_IN_MOVED_TO(self, event):
            try:
                tree, path = WorkingTree.open_containing(event.src_pathname)
                root = event.src_pathname[:-len(path)] # Ugh, hackish
    
                if not path.startswith(".bzr"): # Also hackish (to exclude events for anything in the .bzr subdirectory)
                    try:
                        tree.lock_tree_write()
                        source = event.src_pathname[len(root):] # Again hackish
                        target = event.pathname[len(root):] # Same
                        tree.rename_one(source, target)
                        print "Renamed %s to %s" % (source, target)
                    except BzrRenameFailedError: # Same
                        pass
                    finally:
                        tree.unlock()
            except NotBranchError:
                return
    
    handler = EventHandler()
    notifier = pyinotify.Notifier(wm, handler)
    
    for path in directories_to_watch:
        wdd = wm.add_watch(path, mask, rec=True, auto_add=True)
        print "Recursively watching %s" % path
    
    notifier.loop()
    

    Here’s how it works:

    $ mv afile bfile
    $ bzr status
    renamed:
      afile => bfile
    
    $ mv bfile foobar/
    $ bzr status
    renamed:
      afile => foobar/bfile
    
    $ mv foobar/ zoobar
    $ bzr status
    renamed:
      afile => zoobar/bfile
      foobar/ => zoobar/
    
    $ mv zoobar/ foobar
    $ bzr status
    renamed:
      afile => foobar/bfile
    
    $ mv foobar/bfile afile
    

    And we’re back where we got started 😉

    [edit]

    If you don’t want to manually list the various directories to watch it might be a good idea to write a Nautilus extension which keeps track of the various working copies it encounters as you navigate. Here’s something to get you started (this goes into ~/.nautilus/python-extensions):

    import os
    import pickle
    
    import nautilus 
    
    import gio
    
    from xdg import BaseDirectory as basedir
    
    import bzrlib
    from bzrlib.workingtree import WorkingTree
    from bzrlib.errors import NotBranchError
    
    class BzrMonitor(nautilus.InfoProvider, nautilus.MenuProvider):
    
        data_directory = basedir.save_data_path("bzrmonitor")
        data_filename = os.path.join(data_directory, "workingcopies.db")
    
        def __init__(self):
            print "Initializing BzrMonitor extension..."
    
            try:
                data_file = open(self.data_filename, "r")
                self.data = pickle.load(data_file)
            except IOError:
                self.data = []
                data_file = open(self.data_filename, "w")
                pickle.dump(self.data, data_file)
                data_file.close()
    
        def detect_and_save_branch(self, path):
            try:
                tree, rel_path = WorkingTree.open_containing(path)
    
                # TODO: Still can't figure out how to get the path from the tree itself
                if len(rel_path) > 0: 
                    root = path[:-len(rel_path)]
                else:
                    root = path
    
                root = root.rstrip(os.path.sep)
    
                if root not in self.data: 
                    print "Added not seen before branch %s to cache..." % root
                    self.data.append(root)
                    data_file = open(self.data_filename, "w")
                    pickle.dump(self.data, data_file)
                    data_file.close()
    
            except NotBranchError:
                return
    
        def update_file_info(self, item):
            """
            This function is called when:
    
              - When you enter a directory (once for each item but only when the
                item was modified since the last time it was listed)
              - When you refresh (once for each item visible)
              - When an item viewable from the current window is created or modified
            """
            self.detect_and_save_branch(gio.File(item.get_uri()).get_path())
    
        def get_file_items(self, window, items):
            """
            Menu activated with items selected. Nautilus also calls this function
            when rendering submenus, even though this is not needed since the entire
            menu has already been returned.
            """
    
            pass
    
        def get_background_items(self, window, item):
            """
            Menu activated on entering a directory. Builds context menu for File
            menu and for window background.
            """
    
            self.detect_and_save_branch(gio.File(item.get_uri()).get_path())
    

    I borrowed the various docstrings from RabbitVCS’s extension code 😉

    In your monitor you’ll probably want to watch the workingcopies.db file for additions and register watches on any new working copies it has found.

    Resources

    • pyinotify
    • API Documentation for Bazaar
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using XNA but it doesn't matter too much for this example. So let's
$class = new Class; $foo = json_decode($_POST['array']); In this highly contrived example, I have
So I have been reading all i can for the last 2 hours and
I have names of all files in output.txt but I do not have folderpath
I am started working on resume retrieval(document) component based on lucene.net engine. It works
Is there a way that we can drag text or images onto the desktop
One of the challenges I see over and over again is a company with
For my tile-based game, I need to calculate direction based on a given point
Given an arbitary peg solitaire board configuration, what is the most effecient way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.