43
43
from all .utils .readconfig import read_config
44
44
from all .utils .repofactory import get_repository
45
45
from all .utils .utils import is_exe , check_create_dir , get_int , diff_list
46
+ from all .scm .repository import RepositoryException
47
+
46
48
47
49
major_version = sys .version_info [0 ]
48
- if ( major_version < 3 ) :
50
+ if major_version < 3 :
49
51
print ("Need Python 3, you are running {}" .format (major_version ))
50
52
sys .exit (1 )
51
53
52
- __version__ = "0.2 "
54
+ __version__ = "0.3 "
53
55
54
56
# "constants"
55
57
HOOK_TIMEOUT_PROPERTY = 'hook_timeout'
68
70
CONTINUE_EXITVAL = 2
69
71
70
72
71
- def get_repos_for_project (logger , project , source_root , config , proxy ,
72
- command_timeout , ignored_repos , uri ):
73
+ def get_repos_for_project (logger , project , ignored_repos , ** kwargs ):
73
74
"""
74
75
:param logger: logger
75
76
:param project: project name
76
- :param source_root: source root path
77
- :param config: configuration dictionary
78
- :param proxy: proxy
79
- :param command_timeout: command timeout
80
77
:param ignored_repos: list of ignored repositories
81
- :param uri: URI for the web application
82
- :return: tuple of lists of Repository objects and return value
83
- (1 on failure, 0 on success)
78
+ :param kwargs: argument dictionary
79
+ :return: list of Repository objects
84
80
"""
85
81
repos = []
86
- ret = 0
87
- for repo_path in get_repos (logger , project , uri ):
82
+ for repo_path in get_repos (logger , project , kwargs ['uri' ]):
88
83
logger .debug ("Repository path = {}" .format (repo_path ))
89
84
90
85
if repo_path in ignored_repos :
91
86
logger .info ("repository {} ignored" .format (repo_path ))
92
87
continue
93
88
94
- repo_type = get_repo_type (logger , repo_path , uri )
89
+ repo_type = get_repo_type (logger , repo_path , kwargs [ ' uri' ] )
95
90
if not repo_type :
96
- logger .error ("cannot determine type of {}" .
97
- format (repo_path ))
98
- continue
91
+ raise RepositoryException ("cannot determine type of repository {}" .
92
+ format (repo_path ))
99
93
100
94
logger .debug ("Repository type = {}" .format (repo_type ))
101
95
102
96
repo = get_repository (logger ,
103
- source_root + repo_path ,
97
+ # Not joining the path since the form
98
+ # of repo_path is absolute path.
99
+ kwargs ['source_root' ] + repo_path ,
104
100
repo_type ,
105
101
project ,
106
- config . get ( COMMANDS_PROPERTY ) ,
107
- proxy ,
102
+ kwargs [ 'commands' ] ,
103
+ kwargs [ ' proxy' ] ,
108
104
None ,
109
- command_timeout )
105
+ kwargs [ ' command_timeout' ] )
110
106
if not repo :
111
- logger .error ("Cannot get repository for {}" .
112
- format (repo_path ))
113
- ret = 1
107
+ raise RepositoryException ("Cannot get repository for {}" .
108
+ format (repo_path ))
114
109
else :
115
- repos .add (repo )
110
+ repos .append (repo )
116
111
117
- return repos , ret
112
+ return repos
118
113
119
114
120
115
def main ():
@@ -133,6 +128,9 @@ def main():
133
128
help = 'batch mode - will log into a file' )
134
129
parser .add_argument ('-B' , '--backupcount' , default = 8 ,
135
130
help = 'how many log files to keep around in batch mode' )
131
+ parser .add_argument ('-I' , '--incoming' , action = 'store_true' ,
132
+ help = 'Check for incoming changes, terminate the '
133
+ 'processing if not found.' )
136
134
args = parser .parse_args ()
137
135
138
136
if args .debug :
@@ -166,10 +164,10 @@ def main():
166
164
167
165
uri = args .uri
168
166
if not uri :
169
- logger .error ("uri of the webapp not specified" )
167
+ logger .error ("URI of the web application not specified" )
170
168
sys .exit (1 )
171
169
172
- logger .debug ("Uri = {}" .format (uri ))
170
+ logger .debug ("URI = {}" .format (uri ))
173
171
174
172
source_root = get_config_value (logger , 'sourceRoot' , uri )
175
173
if not source_root :
@@ -251,7 +249,7 @@ def main():
251
249
252
250
ignored_repos = project_config .get (IGNORED_REPOS_PROPERTY )
253
251
if ignored_repos :
254
- if type (ignored_repos ) is not list :
252
+ if not isinstance (ignored_repos , list ) :
255
253
logger .error ("{} for project {} is not a list" .
256
254
format (IGNORED_REPOS_PROPERTY , args .project ))
257
255
sys .exit (1 )
@@ -347,18 +345,46 @@ def main():
347
345
# Cache the repositories first. This way it will be known that
348
346
# something is not right, avoiding any needless pre-hook run.
349
347
#
350
- repos , ret = get_repos_for_project (logger , args .project ,
351
- source_root , config , proxy ,
352
- command_timeout , ignored_repos ,
353
- uri )
354
- if ret == 1 :
355
- # The error was already logged in get_repos_for_project()
348
+ repos = []
349
+ try :
350
+ repos = get_repos_for_project (logger , args .project ,
351
+ ignored_repos ,
352
+ commands = config .
353
+ get (COMMANDS_PROPERTY ),
354
+ proxy = proxy ,
355
+ command_timeout = command_timeout ,
356
+ source_root = source_root ,
357
+ uri = uri )
358
+ except RepositoryException :
359
+ logger .error ('failed to get repositories for project {}' .
360
+ format (args .project ))
356
361
sys .exit (1 )
357
- if len (repos ) == 0 :
362
+
363
+ if not repos :
358
364
logger .info ("No repositories for project {}" .
359
365
format (args .project ))
360
366
sys .exit (CONTINUE_EXITVAL )
361
367
368
+ # Check if any of the repositories contains incoming changes.
369
+ if args .incoming :
370
+ got_incoming = False
371
+ for repo in repos :
372
+ try :
373
+ if repo .incoming ():
374
+ logger .debug ('Repository {} has incoming changes' .
375
+ format (repo ))
376
+ got_incoming = True
377
+ break
378
+ except RepositoryException :
379
+ logger .error ('Cannot determine incoming changes for '
380
+ 'repository {}, driving on' .format (repo ))
381
+
382
+ if not got_incoming :
383
+ logger .info ('No incoming changes for repositories in '
384
+ 'project {}' .
385
+ format (args .project ))
386
+ sys .exit (CONTINUE_EXITVAL )
387
+
362
388
if prehook :
363
389
logger .info ("Running pre hook" )
364
390
if run_hook (logger , prehook ,
@@ -374,12 +400,12 @@ def main():
374
400
# is treated as failed, i.e. the program will return 1.
375
401
#
376
402
for repo in repos :
377
- logger .info ("Synchronizing repository {}" .
378
- format (repo .path ))
379
- if repo .sync () != 0 :
380
- logger .error ("failed to sync repository {}" .
381
- format (repo .path ))
382
- ret = 1
403
+ logger .info ("Synchronizing repository {}" .
404
+ format (repo .path ))
405
+ if repo .sync () != 0 :
406
+ logger .error ("failed to sync repository {}" .
407
+ format (repo .path ))
408
+ ret = 1
383
409
384
410
if posthook :
385
411
logger .info ("Running post hook" )
0 commit comments