"Fossies" - the Fresh Open Source Software Archive

Member "unicore-ucc-8.0.2/extras/emacs-mode/ucc-mode.el" (18 May 2020, 11773 Bytes) of package /linux/misc/unicore-ucc-8.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 ;;; ucc-mode.el --- access ucc from within Emacs
    2 
    3 ;; Copyright (C) 2008 Rebecca Breu, Research Centre Juelich
    4 
    5 ;; Maintainer: 2008 Rebecca Breu, Research Centre Juelich
    6 ;; Keywords: unicore, ucc
    7 ;; Created: 2008-03-31
    8 ;; Modified: 2008-03-31
    9 ;; X-URL: http://www.unicore.eu
   10 
   11 ;;; License
   12 
   13 ;; This program is free software; you can redistribute it and/or
   14 ;; modify it under the terms of the GNU General Public License
   15 ;; as published by the Free Software Foundation; either version 2
   16 ;; of the License, or (at your option) any later version.
   17 
   18 ;; This program is distributed in the hope that it will be useful,
   19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
   20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21 ;; GNU General Public License for more details.
   22 
   23 ;; You should have received a copy of the GNU General Public License
   24 ;; along with this program; if not, write to the Free Software
   25 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   26 
   27 (require 'ucc-localfilelist-mode)
   28 (require 'ucc-output-mode)
   29 (require 'cl)
   30 (require 'custom)
   31 
   32 ;; General configuration:
   33 
   34 (defgroup ucc nil
   35   "Run ucc (UNICORE command line client) from within Emacs."
   36   :group 'tools
   37   :group 'processes)
   38   
   39 
   40 (defcustom ucc-command "/usr/bin/ucc"
   41   "Path to the ucc executable."
   42   :type 'file
   43   :group 'ucc)
   44 
   45 (defcustom ucc-flags ""
   46   "String of flags passed to every ucc call, i.e.:
   47 
   48 ucc <command> <ucc-flags> ...
   49 
   50 For example, set it to \"-v\" for verbose output, to
   51 \"-c /path/to/preferences\" to specify the configuration file used,
   52 or leave it an empty string."
   53   :type 'string
   54   :group 'ucc)
   55 
   56 (defcustom ucc-reuse-buffer t
   57   "If nil, create a new output buffer for each ucc process.
   58 
   59 If non-nil, reuse old buffer. This way, only one process may run at
   60 any time, and old output will be overwritten."
   61   :type 'boolean
   62   :group 'ucc)
   63 
   64 
   65 ;; Setting up general key bindings and menus:
   66 
   67 (defvar ucc-workflow-submenu
   68   (let ((map (make-sparse-keymap)))
   69     (define-key map [workflow-info]
   70       '("Workflow info" . ucc-workflow-info))
   71     (define-key map [submit-file]
   72       '("Submit workflow file" . ucc-workflow-submit-file))
   73     map)
   74   "Keymap for workflow submenu in ucc minor mode.")
   75 
   76 
   77 (defvar ucc-mode-map 
   78   (let ((map (make-sparse-keymap)))
   79     ;; keybindings:
   80     (define-key map (kbd "C-c C-c") 'ucc-connect)
   81     (define-key map (kbd "C-c C-r") 'ucc-run-file)
   82     (define-key map (kbd "C-c C-g") 'ucc-run-groovy-file)
   83     (define-key map (kbd "C-c C-j") 'ucc-list-jobs)
   84     (define-key map (kbd "C-c C-t") 'ucc-list-sites)
   85     (define-key map (kbd "C-c C-p") 'ucc-list-applications)
   86     (define-key map (kbd "C-c C-y") 'ucc-system-info)
   87     (define-key map (kbd "C-c C-s") 'ucc-get-status)
   88     (define-key map (kbd "C-c C-o") 'ucc-get-output)
   89     (define-key map (kbd "C-c C-f") 'ucc-get-file)
   90     (define-key map (kbd "C-c C-a") 'ucc-abort-job)
   91     (define-key map (kbd "C-c C-d") 'ucc-destroy-job)
   92     (define-key map (kbd "C-c C-l") 'ucc-list-remote-file)
   93     (define-key map (kbd "C-c C-u") 'ucc)
   94     (define-key map (kbd "C-c C-w") 'ucc-workflow-submit-file)
   95     (define-key map (kbd "C-c C-n") 'ucc-workflow-info)
   96     ;; ucc menu in menu bar:
   97     (define-key map [menu-bar ucc] (cons "ucc" (make-sparse-keymap)))
   98     (define-key map [menu-bar ucc customize]
   99       '("Customize ucc-mode..." . (lambda ()
  100                     (interactive)
  101                     (customize-group "ucc"))))
  102     (define-key map [menu-bar ucc customize-seperator] '("---"))
  103     (define-key map [menu-bar ucc ucc] '("General ucc command..." . ucc))
  104 ;;    (define-key map [menu-bar ucc wf-seperator] '("---"))
  105     (define-key map [menu-bar ucc wf]
  106       (list 'menu-item "Workflow" ucc-workflow-submenu))
  107     (define-key map [menu-bar ucc general-seperator] '("---"))
  108     (define-key map [menu-bar ucc list-storages]
  109       '("List storages" . ucc-list-storages))
  110     (define-key map [menu-bar ucc list-remote-dir]
  111       '("List remote file or dir..." . ucc-list-remote-file))
  112     (define-key map [menu-bar ucc data-manage-seperator]
  113       '("---"))
  114     (define-key map [menu-bar ucc destroy-job]
  115       '("Destroy job..." . ucc-destroy-job))
  116     (define-key map [menu-bar ucc abort-job]
  117       '("Abort job..." . ucc-abort-job))
  118     (define-key map [menu-bar ucc get-file]
  119       '("Get file..." . ucc-get-file))
  120     (define-key map [menu-bar ucc get-output]
  121       '("Get output..." . ucc-get-output))
  122     (define-key map [menu-bar ucc get-status]
  123       '("Get status..." . ucc-get-status))
  124     (define-key map [menu-bar ucc list-jobs]
  125       '("List jobs" . ucc-list-jobs))
  126     (define-key map [menu-bar ucc job-manage-seperator]
  127       '("---"))
  128     (define-key map [menu-bar ucc run-groovy-file-at-site]
  129       '("Run groovy file at site..." . ucc-run-groovy-file-at-site))
  130     (define-key map [menu-bar ucc run-groovy-file]
  131       '("Run groovy file" . ucc-run-groovy-file))
  132     (define-key map [menu-bar ucc run-file-at-site]
  133       '("Run file at site..." . ucc-run-file-at-site))
  134     (define-key map [menu-bar ucc run-file]
  135       '("Run file" . ucc-run-file))
  136     (define-key map [menu-bar ucc submit-seperator]
  137       '("---"))
  138     (define-key map [menu-bar ucc system-info]
  139       '("System info" . ucc-system-info))
  140     (define-key map [menu-bar ucc list-sites]
  141       '("List sites" . ucc-list-sites))
  142     (define-key map [menu-bar ucc list-applications]
  143       '("List applications" . ucc-list-applications))
  144     (define-key map [menu-bar ucc connect]
  145       '("Connect" . ucc-connect))
  146     map)
  147   "Keymap for ucc minor mode.")
  148 
  149 
  150 
  151 ;; Setting up minor mode:
  152 
  153 (define-minor-mode ucc-mode
  154   "Toggle ucc-mode.
  155 
  156 ucc-mode is a minor mode which provides a menu and shortcuts for accessing
  157 the ucc-* functions. It is not part of GNU Emacs.
  158 
  159 The ucc-* functions call the external UNICORE command line client.
  160 Before first usage, make sure that the variable ucc-command points to
  161 your ucc executable.
  162 
  163 See www.unicore.eu for further information on UNICORE.
  164 
  165 \\{ucc-mode-map}
  166 "
  167   :init-value nil
  168   :lighter ""
  169   :keymap 'ucc-mode-map
  170   :group 'ucc
  171   )
  172 
  173 
  174 
  175 
  176 ;; Internal functions and variables for calling external ucc executable:
  177 
  178 (defvar ucc-running-process nil
  179   "Points to the running ucc process or nil.")
  180 
  181 
  182 (defun ucc-sentinel (process string)
  183   "Keep track if ucc process exits and set ucc-running-process accordingly."
  184   (if (eq (process-status process) 'exit)
  185       (save-excursion
  186         (setq ucc-running-process nil)
  187         (set-buffer (process-buffer process))
  188         (goto-char (point-max))
  189         (insert "\n--- UCC finished at ")
  190         (insert (format-time-string "%Y-%m-%dT%T%z\n" (current-time))))))
  191 
  192 
  193 (defun* ucc-start-process (buffermode command &rest args)
  194   "Start ucc asynchronously, put output buffer in mode BUFFERMODE.
  195 If there is already a ucc process running, ask user to terminate it.
  196 
  197 COMMAND is the ucc command, ARGS are further arguments passed to ucc."
  198 
  199   (let ((buffer nil))
  200     (if ucc-reuse-buffer
  201     (progn
  202       (if ucc-running-process
  203           (if (not (yes-or-no-p
  204             "There is already a ucc process running. Terminate it? "))
  205           (error "Aborted")
  206         (signal-process (process-id ucc-running-process) 'SIGINT)))
  207       (setq buffer (get-buffer-create "*ucc*")))
  208       (setq buffer (generate-new-buffer "*ucc*")))
  209 
  210     (set-buffer buffer)
  211     (apply buffermode nil)
  212     (ucc-mode t)
  213     (erase-buffer)
  214     (let* ((process-connection-type nil) ;; use pipe
  215        (process
  216         (apply 'start-process-shell-command
  217            (append
  218             (list "ucc" buffer ucc-command command ucc-flags)
  219             args))))
  220       (setq ucc-running-process process)
  221       (set-process-sentinel process 'ucc-sentinel))
  222     (display-buffer buffer)))
  223 
  224 
  225 ;; ucc functions:
  226 
  227 (defun ucc-connect ()
  228   "Connect to UNICORE."
  229   (interactive)
  230   (ucc-start-process 'ucc-output-mode "connect"))
  231 
  232 
  233 (defun ucc-list-jobs ()
  234   "List your jobs."
  235   (interactive)
  236   (ucc-start-process 'ucc-output-mode "list-jobs"))
  237 
  238 
  239 (defun ucc-list-sites ()
  240   "List remote sites."
  241   (interactive)
  242   (ucc-start-process 'ucc-output-mode "list-sites"))
  243 
  244 
  245 (defun ucc-list-applications ()
  246   "Lists applications on target systems."
  247   (interactive)
  248   (ucc-start-process 'ucc-output-mode "list-applications"))
  249 
  250 
  251 (defun ucc-get-status (job)
  252   "Get job status of JOB.
  253 
  254 JOB is an EPR (endpoint reference)."
  255   (interactive "MJob identifier: ")
  256   (ucc-start-process 'ucc-output-mode "job-status" (format "\"%s\"" job)))
  257   
  258 
  259 (defun ucc-get-output (job)
  260   "Get output files of JOB.
  261 
  262 JOB is an EPR (endpoint reference)."
  263   (interactive "MJob identifier: ")
  264   (ucc-start-process 'ucc-localfilelist-mode "get-output" 
  265              (format "\"%s\"" job)))
  266   
  267 
  268 (defun ucc-abort-job (job)
  269   "Abort JOB.
  270 
  271 JOB is an EPR (endpoint reference)."
  272   (interactive "MJob identifier: ")
  273   (ucc-start-process 'ucc-output-mode "job-abort" (format "\"%s\"" job)))
  274   
  275 
  276 (defun ucc-destroy-job (job)
  277   "Destroy JOB.
  278 
  279 JOB is an EPR (endpoint reference)."
  280   (interactive "MJob identifier: ")
  281   (ucc-start-process 'ucc-output-mode "wsrf" "destroy" (format "\"%s\"" job)))
  282   
  283 
  284 (defun ucc-run-file ()
  285   "Run the ucc job file in the current buffer."
  286   (interactive)
  287   (if (not buffer-file-name)
  288       (error "Buffer is not associated with any file")
  289     (ucc-start-process 'ucc-localfilelist-mode "run" 
  290                (format "\"%s\"" buffer-file-name))))
  291 
  292 
  293 (defun ucc-run-file-at-site (sitename)
  294   "Run the ucc job file in the current buffer at SITENAME."
  295   (interactive "MSite name: ")
  296   (if (not buffer-file-name)
  297       (error "Buffer is not associated with any file")
  298     (ucc-start-process 'ucc-localfilelist-mode "run"
  299                "-s" (format "\"%s\"" sitename)
  300                (format "\"%s\"" buffer-file-name))))
  301 
  302 
  303 (defun ucc-run-groovy-file ()
  304   "Run the groovy script in the current buffer."
  305   (interactive)
  306   (if (not buffer-file-name)
  307       (error "Buffer is not associated with any file")
  308     (ucc-start-process 'ucc-localfilelist-mode "run-groovy"
  309                "-f" (format "\"%s\"" buffer-file-name))))
  310 
  311 
  312 (defun ucc-run-groovy-file-at-site (sitename)
  313   "Run the groovy script in the current buffer at SITENAME."
  314   (interactive "MSite name: ")
  315   (if (not buffer-file-name)
  316       (error "Buffer is not associated with any file")
  317     (ucc-start-process 'ucc-localfilelist-mode "run-groovy"
  318                "-s" (format "\"%s\"" sitename)
  319                (format "\"%s\"" buffer-file-name))))
  320 
  321 
  322 (defun ucc-list-remote-file (file)
  323   "List FILE on a remote site.
  324 
  325 FILE is the file or directory specified in the form
  326 \"u6://SITE/path/to/dir\"
  327 or as an end point reference."
  328   (interactive "MRemote File or Directory: ")
  329   (ucc-start-process 'ucc-output-mode "ls" "-l" (format "\"%s\"" file)))
  330 
  331 
  332 (defun ucc-list-storages ()
  333   "List available storages."
  334   (interactive)
  335   (ucc-start-process 'ucc-output-mode "list-storages" "-l"))
  336 
  337 
  338 (defun ucc-system-info ()
  339   "Check the availability of services."
  340   (interactive)
  341   (ucc-start-process 'ucc-output-mode "system-info" "-l"))
  342 
  343 
  344 (defun ucc (parameters)
  345   "Run an arbitrary ucc command.
  346 
  347 Pass PARAMETERS to the ucc call, e.g. \"run -v date.u\"."
  348   (interactive "MParameters to pass to ucc: ")
  349   (ucc-start-process 'ucc-output-mode parameters))
  350 
  351 
  352 (defun ucc-workflow-submit-file ()
  353   "Submit the worklow file in the current buffer."
  354   (interactive)
  355   (if (not buffer-file-name)
  356       (error "Buffer is not associated with any file")
  357     (ucc-start-process 'ucc-output-mode "workflow-submit" 
  358                (format "\"%s\"" buffer-file-name))))
  359 
  360 
  361 (defun ucc-workflow-info ()
  362   "List submitted workflows."
  363   (interactive)
  364   (ucc-start-process 'ucc-output-mode "workflow-info" "-l"))
  365 
  366 (defun ucc-get-file (src dst)
  367   "Get a file from a storage.
  368 
  369 SRC is the data source, DST is the data target."
  370   (interactive "MSource: \nMTarget: ")
  371   (ucc-start-process 'ucc-output-mode "get-file"
  372              "-s" (format "\"%s\"" src)
  373              "-t" (format "\"%s\"" dst)))
  374 
  375 
  376 (provide 'ucc-mode) 
  377     
  378