File tree 4 files changed +23
-6
lines changed
4 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -26,13 +26,18 @@ _jenkins()
26
26
case $prev in
27
27
jobs)
28
28
opts=" -h --help -a -p"
29
- COMPREPLY=($( compgen -W " ${opts} " -- ${cur} ) )
30
- return 0
31
29
;;
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)
33
40
opts=" -h --help"
34
- COMPREPLY=($( compgen -W " ${opts} " -- ${cur} ) )
35
- return 0
36
41
;;
37
42
esac
38
43
Original file line number Diff line number Diff line change 6
6
import jenkins
7
7
import socket
8
8
from xml .etree import ElementTree
9
+ from xdg .BaseDirectory import save_cache_path
9
10
10
11
STATUSES_COLOR = {'blue' : {'symbol' : 'S' ,
11
12
'color' : '\033 [94m' ,
@@ -77,6 +78,7 @@ class CliException(Exception):
77
78
78
79
class JenkinsCli (object ):
79
80
SETTINGS_FILE_NAME = '.jenkins-cli'
81
+ JOB_CACHE_FILE_NAME = 'job_cache'
80
82
81
83
QUEUE_EMPTY_TEXT = "Building queue is empty"
82
84
@@ -129,10 +131,18 @@ def run_command(self, args):
129
131
130
132
def jobs (self , args ):
131
133
jobs = self ._get_jobs (args )
134
+
135
+ # print jobs
132
136
for job in jobs :
133
137
formated_status = get_formated_status (job ['color' ])
134
138
print (formated_status + " " + job ['name' ])
135
139
140
+ # save job names to cache file
141
+ our_cache_dir = save_cache_path ('python-jenkins-cli' )
142
+ job_cache_file = os .path .join (our_cache_dir , self .JOB_CACHE_FILE_NAME )
143
+ with open (job_cache_file , 'w' ) as f :
144
+ f .write (' ' .join (job ['name' ] for job in jobs ))
145
+
136
146
def _get_jobs (self , args ):
137
147
jobs = self .jenkins .get_jobs ()
138
148
if args .a :
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ pyfakefs==2.7.0
4
4
mock == 2.0.0
5
5
unittest2 == 1.1.0
6
6
flake8 == 2.5.4
7
+ pyxdg == 0.25
Original file line number Diff line number Diff line change 15
15
raise RuntimeError ('Unable to find version string.' )
16
16
17
17
requires = ['python-jenkins==0.4.14' ,
18
- 'six>=1.9.0' ]
18
+ 'six>=1.9.0' ,
19
+ 'pyxdg>=0.25' ]
19
20
20
21
tests_require = ['unittest2==1.1.0' ,
21
22
'mock==2.0.0' ,
You can’t perform that action at this time.
0 commit comments