File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,13 +26,18 @@ _jenkins()
2626 case $prev in
2727 jobs)
2828 opts=" -h --help -a -p"
29- COMPREPLY=($( compgen -W " ${opts} " -- ${cur} ) )
30- return 0
3129 ;;
32- queue|building|builds|start|info|configxml|setbranch|stop|console|changes)
30+ builds|start|info|configxml|setbranch|stop|console|changes)
31+ opts=" -h --help"
32+
33+ # if the cached-jobs file exists suggest also job names
34+ CACHE_DIR=${XDG_CACHE_HOME:- ~/ .cache} " /python-jenkins-cli"
35+ if [ -r $CACHE_DIR /job_cache ]; then
36+ opts=" $opts $( cat $CACHE_DIR /job_cache) "
37+ fi
38+ ;;
39+ queue|building)
3340 opts=" -h --help"
34- COMPREPLY=($( compgen -W " ${opts} " -- ${cur} ) )
35- return 0
3641 ;;
3742 esac
3843
Original file line number Diff line number Diff line change 66import jenkins
77import socket
88from xml .etree import ElementTree
9+ from xdg .BaseDirectory import save_cache_path
910
1011try :
1112 from ConfigParser import ConfigParser , NoSectionError
@@ -83,6 +84,7 @@ class CliException(Exception):
8384
8485class JenkinsCli (object ):
8586 SETTINGS_FILE_NAME = '.jenkins-cli'
87+ JOB_CACHE_FILE_NAME = 'job_cache'
8688
8789 QUEUE_EMPTY_TEXT = "Building queue is empty"
8890
@@ -144,10 +146,18 @@ def run_command(self, args):
144146
145147 def jobs (self , args ):
146148 jobs = self ._get_jobs (args )
149+
150+ # print jobs
147151 for job in jobs :
148152 formated_status = get_formated_status (job ['color' ])
149153 print (formated_status + " " + job ['name' ])
150154
155+ # save job names to cache file
156+ our_cache_dir = save_cache_path ('python-jenkins-cli' )
157+ job_cache_file = os .path .join (our_cache_dir , self .JOB_CACHE_FILE_NAME )
158+ with open (job_cache_file , 'w' ) as f :
159+ f .write (' ' .join (job ['name' ] for job in jobs ))
160+
151161 def _get_jobs (self , args ):
152162 jobs = self .jenkins .get_jobs ()
153163 if args .a :
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ pyfakefs==2.7.0
44mock == 2.0.0
55unittest2 == 1.1.0
66flake8 == 2.5.4
7+ pyxdg == 0.25
Original file line number Diff line number Diff line change 1515 raise RuntimeError ('Unable to find version string.' )
1616
1717requires = ['python-jenkins==0.4.14' ,
18- 'six>=1.9.0' ]
18+ 'six>=1.9.0' ,
19+ 'pyxdg>=0.25' ]
1920
2021tests_require = ['unittest2==1.1.0' ,
2122 'mock==2.0.0' ,
You can’t perform that action at this time.
0 commit comments