-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreposnapshot
executable file
·83 lines (57 loc) · 2.21 KB
/
reposnapshot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python
# Copyright (C) 2011 Javier Palacios
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License Version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
__version__ = "1.0"
__usage__ = """%prog reponame snapshotname"""
import sys
import repolib
import optparse
def option_parser () :
version_string = "%%prog %s" % __version__
parser = optparse.OptionParser( usage=__usage__ , version=version_string )
parser.add_option( "--quiet" , action="store_true" ,
help="Issue only critical messages" )
parser.add_option( "--verbose" , action="store_true" ,
help="Run in descriptive mode" )
return parser
def main () :
parser = option_parser()
opts , args = parser.parse_args()
if len(args) != 2 :
parser.print_help()
sys.exit(1)
if opts.verbose and opts.quiet :
repolib.logger.warning( "Specified verbose and quiet simultaneously, switching to quiet" )
if opts.verbose :
repolib.logger.setLevel( repolib.logging.INFO )
if opts.quiet :
repolib.logger.setLevel( repolib.logging.ERROR )
if args[1] in repolib.config.get_all_build_repos() :
repolib.logger.error( "Snapshot %s : repository already exists" % args[1] )
sys.exit(-1)
try :
repo = repolib.MirrorRepository.new( args[0] )
repo.set_mode( "keep" )
except Exception , ex :
repolib.logger.error( "Repo %s : %s" % ( args[0] , ex ) )
sys.exit(-1)
try :
config = { 'type':"snapshot" , 'source':repo.name }
config.update( repo.dump_conf() )
repolib.config.write_build( args[1] , config , ( 'url' , 'subdir' ) )
snapshot = repolib.BuildRepository.new( args[1] )
snapshot.force = True
except Exception , ex :
repolib.logger.error( "Snapshot %s : %s" % ( args[1] , ex ) )
sys.exit(-1)
snapshot.build()
if __name__ == "__main__" :
main()