Steve Borho avatar Steve Borho committed 2a14316

hggtk/thgconfig: simplify specification of user/repo mode on command line

If file list is provided, assume repository configure mode, else assume user configure mode.
This gets rid of a lot of ugly hacks in hgproc.py and the nautilus extension, and prevents
me from adding even uglier hacks to the context menu code.

Comments (0)

Files changed (3)

hggtk/thgconfig.py

         self.dirty = False
         return 0
 
-def run(root='', cmdline=[], **opts):
+def run(root='', cmdline=[], files=[], **opts):
     if '--focusfield' in cmdline:
         field = cmdline[cmdline.index('--focusfield')+1]
     else:
         field = None
-    dialog = ConfigDialog(root, '--configrepo' in cmdline, field)
+    dialog = ConfigDialog(root, bool(files), field)
     dialog.show_all()
     dialog.connect('response', gtk.main_quit)
     gtk.gdk.threads_init()
 if __name__ == "__main__":
     # example command lines
     # python hggtk/thgconfig.py --focusfield ui.editor
-    # python hggtk/thgconfig.py . --focusfield paths.default --configrepo
+    # python hggtk/thgconfig.py --focusfield paths.default --configrepo
     import sys
     opts = {}
-    opts['root'] = len(sys.argv) > 1 and sys.argv[1] or ''
+    opts['root'] = os.getcwd()
     opts['cmdline'] = sys.argv
+    opts['files'] = '--configrepo' in sys.argv and ['.'] or []
     run(**opts)
 def get_option(args):
     import getopt
     long_opt_list = ('command=', 'exepath=', 'listfile=', 'title=',
-                      'root=', 'cwd=', 'notify', 'deletelistfile',
-                      'configrepo')
+                      'root=', 'cwd=', 'notify', 'deletelistfile')
     opts, args = getopt.getopt(args, "c:e:l:ndt:R:", long_opt_list)
     # Set default options
     options = {}
             options['root'] = a
         elif o in ("--cwd"):
             options['cwd'] = a
-        elif o in ("--configrepo"):
-            args.append(o)
 
     if listfile:
         options['files'] = get_list_from_file(listfile)
         self._run_dialog('synch', [vfs_file], filelist=False)
 
     def _thgconfig_repo_cb(self, window, vfs_file):
-        self._run_dialog('config', [vfs_file], args=['--configrepo'])
+        self._run_dialog('config', [vfs_file])
 
     def _thgconfig_user_cb(self, window, vfs_file):
         self._run_dialog('config', [vfs_file], filelist=False)
         else:
             subprocess.Popen(['hg', 'view'], shell=False, cwd=cwd)
 
-    def _run_dialog(self, hgcmd, vfs_files, filelist=True, args=[]):
+    def _run_dialog(self, hgcmd, vfs_files, filelist=True):
         '''
         hgcmd - hgproc subcommand
         vfs_files - directory, or list of selected files
+        filelist  - bool for whether to generate file list for hgproc
         '''
         paths = [self.get_path_for_vfs_file(f) for f in vfs_files]
         if paths[0] is None:
         cmdopts += ['--root', repo.root]
         cmdopts += ['--cwd', cwd]
         cmdopts += ['--command', hgcmd]
-        cmdopts.extend(args)
 
         if filelist:
             # Use temporary file to store file list (avoid shell command
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.