@@ -14,73 +14,16 @@ from datetime import datetime
1414basedir = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
1515
1616try :
17- sys .path .append (basedir + '/lib/python3.3 /site-packages' )
17+ sys .path .append (basedir + '/lib/python3.4 /site-packages' )
1818 from rsync import *
19- import getpass
19+ from git import *
20+ #import getpass
2021except ImportError as err :
2122 print ("Error: %s" % (err ))
2223
2324CONFIG_DIR = basedir + '/etc'
24- PROJECT_DIR = basedir + '/project'
25- ##############################################
26- class Git ():
27- cmd = []
28- def __init__ (self , workspace = None , logging = None ):
29- self .logging = logging
30- self .workspace = workspace
31- def option (self , opt ):
32- if opt :
33- self .opt = opt
34- def clone (self , uri ):
35- if self .workspace :
36- self .cmd .append ('clone ' + uri + ' ' + self .workspace )
37- return (self )
38- def pull (self ):
39- if self .workspace :
40- os .chdir (self .workspace )
41- self .cmd .append ('pull --progress' )
42- return (self )
43- def reset (self ):
44- self .cmd .append ('reset HEAD --hard' )
45- return (self )
46- def branch (self , branchname = None , op = None ):
47- os .chdir (self .workspace )
48- if branchname :
49- if op == 'delete' :
50- self .cmd .append ('branch -D ' + branchname )
51- elif op == 'new' :
52- self .cmd .append ('checkout -fb ' + branchname + ' --' )
53- else :
54- self .cmd .append ('reset HEAD --hard' )
55- self .cmd .append ('fetch origin' )
56- self .cmd .append ('checkout -f ' + branchname )
57- else :
58- self .cmd .append ('branch' )
59- return (self )
60- def merge (self , branchname ):
61- self .cmd .append ('merge ' + branchname )
62- return (self )
63- def tag (self , tagname ):
64- os .chdir (self .workspace )
65- self .cmd .append ('tag ' + tagname )
66- return (self )
67- def checkout (self , revision = None ):
68- os .chdir (self .workspace )
69- if revision :
70- self .cmd .append ('checkout -f ' + revision )
71- return (self )
72- def debug (self ):
73- cmd = ''
74- for line in self .cmd :
75- cmd += 'git ' + line + '; '
76- return (cmd )
77- def execute (self ):
78- for line in self .cmd :
79- os .system ('git ' + line )
80- self .logging .debug ('git ' + line )
81- self .cmd = []
82- print ("-" )
83-
25+ #PROJECT_DIR = os.path.expanduser('~/project')
26+ ##############################################
8427class Deployment ():
8528 debug = False
8629 def __init__ (self ):
@@ -117,9 +60,8 @@ class Deployment():
11760 #group.add_option('','--testcase', help='logs file.', default='backup.log')
11861 self .parser .add_option_group (group )
11962
120- self .config = self .configure (CONFIG_DIR + '/deployment.cfg' ,'main' )
121- self .scm = self .configure (CONFIG_DIR + '/deployment.cfg' ,'scm' )
122- self .node = self .configure (CONFIG_DIR + '/deployment.cfg' ,'node' )
63+ self .config = self .configure (CONFIG_DIR + '/deployment.cfg' ,'scm' )
64+ self .project = self .configure (CONFIG_DIR + '/deployment.cfg' ,'project' )
12365 self .logging = self .logfile (self .config ['logdir' ]+ '/' + self .config ['logfile' ])
12466
12567 def configure (self ,inifile , section = None ):
@@ -173,7 +115,7 @@ class Deployment():
173115
174116 def buildconfig (self , stage , domain , source ):
175117 try :
176- inifile = PROJECT_DIR + '/config/' + stage + '/' + domain + '.ini'
118+ inifile = os . path . expanduser ( self . project [ 'cfgdir' ] + '/config/' + stage + '/' + domain + '.ini' )
177119 if os .path .exists (inifile ):
178120 sections = self .configure (inifile )
179121 #print(sections)
@@ -200,12 +142,12 @@ class Deployment():
200142 def deploy (self , stage , domain ):
201143 self .logging .info ('deployment ' + self .stage + ' ' + self .domain )
202144 try :
203- inifile = PROJECT_DIR + '/' + stage + '/' + domain [domain .find ('.' )+ 1 :]+ '.ini'
145+ inifile = os . path . expanduser ( self . project [ 'cfgdir' ] + '/' + stage + '/' + domain [domain .find ('.' )+ 1 :]+ '.ini' )
204146 host = domain [:domain .find ('.' )]
205147 conf = self .configure (inifile , host )
206148
207149 if ('source' not in conf ):
208- source = self .node ['source' ] + '/' + stage + '/' + domain
150+ source = self .project ['source' ] + '/' + stage + '/' + domain
209151 else :
210152 source = conf ['source' ]
211153
@@ -250,9 +192,9 @@ class Deployment():
250192 rsync = Rsync ()
251193
252194 if ('option' in conf ):
253- rsync .option ('-auzv --exclude=.git --exclude=.svn ' + conf ['option' ])
195+ rsync .option ('-auzv --exclude=.git --exclude=.svn --exclude=.gitignore ' + conf ['option' ])
254196 else :
255- rsync .option ('-auzv --exclude=.git --exclude=.svn' )
197+ rsync .option ('-auzv --exclude=.git --exclude=.svn --exclude=.gitignore ' )
256198
257199 if ('delete' in conf ):
258200 if conf ['delete' ].lower () in ("yes" , "true" , "y" , "enable" ) :
@@ -262,15 +204,15 @@ class Deployment():
262204 if conf ['logfile' ] :
263205 rsync .logfile (conf ['logfile' ])
264206 else :
265- logdir = self .node ['logdir' ]+ '/' + stage
207+ logdir = os . path . expanduser ( self .project ['logdir' ]+ '/' + stage )
266208 if not os .path .exists (logdir ):
267209 os .makedirs (logdir )
268210 conf ['logfile' ] = logdir + '/' + domain + '.' + datetime .today ().strftime ('%Y-%m-%d' )+ '.log'
269211 #.%H:%M:%S
270212 rsync .logfile (conf ['logfile' ])
271213
272214 if ('password' in conf ):
273- rsync .password (conf ['password' ])
215+ rsync .password (os . path . expanduser ( conf ['password' ]) )
274216
275217 if ('backup' in conf ):
276218 if conf ['backup' ] :
@@ -280,7 +222,7 @@ class Deployment():
280222 rsync .backup (conf ['backup' ])
281223
282224 if ('exclude' in conf ):
283- rsync .exclude (PROJECT_DIR + '/exclude/' + conf ['exclude' ])
225+ rsync .exclude (os . path . expanduser ( self . project [ 'cfgdir' ] + '/exclude/' + conf ['exclude' ]) )
284226
285227 rsync .source (source + '/' )
286228
@@ -308,12 +250,12 @@ class Deployment():
308250 stage = args [1 ]
309251 domain = args [2 ]
310252 try :
311- inifile = PROJECT_DIR + '/' + stage + '/' + domain [domain .find ('.' )+ 1 :]+ '.ini'
253+ inifile = os . path . expanduser ( self . project [ 'cfgdir' ] + '/' + stage + '/' + domain [domain .find ('.' )+ 1 :]+ '.ini' )
312254 host = domain [:domain .find ('.' )]
313255 conf = self .configure (inifile , host )
314256
315257 if ('source' not in conf ):
316- source = self .node ['source' ] + '/' + stage + '/' + domain
258+ source = self .project ['source' ] + '/' + stage + '/' + domain
317259 else :
318260 source = conf ['source' ]
319261
@@ -350,10 +292,10 @@ class Deployment():
350292 domain = args [2 ]
351293
352294 host = domain [:domain .find ('.' )]
353- conf = self .configure (PROJECT_DIR + '/' + stage + '/' + domain [domain .find ('.' )+ 1 :]+ '.ini' , host )
295+ conf = self .configure (os . path . expanduser ( self . project [ 'cfgdir' ] + '/' + stage + '/' + domain [domain .find ('.' )+ 1 :]+ '.ini' , host ) )
354296
355297 workspace = os .path .expanduser ('~/.workspace' )
356- #self.scm
298+
357299 project = workspace + '/' + domain
358300 git = Git (project , self .logging )
359301
@@ -405,9 +347,9 @@ class Deployment():
405347 try :
406348 config = configparser .SafeConfigParser ()
407349 #if domain == None:
408- for file in os .listdir (PROJECT_DIR + '/' + stage ):
350+ for file in os .listdir (os . path . expanduser ( self . project [ 'cfgdir' ] + '/' + stage ) ):
409351 if file .endswith (".ini" ):
410- config .read (PROJECT_DIR + '/' + stage + '/' + file )
352+ config .read (os . path . expanduser ( self . project [ 'cfgdir' ] + '/' + stage + '/' + file ) )
411353 print (file )
412354 #for project in config.sections():
413355 # print(project, end = ', ');
@@ -438,9 +380,9 @@ class Deployment():
438380 if args [1 ] in ('development' ,'testing' ,'production' ):
439381 self .merge (args , self .options .to , self .options .froms )
440382 elif args [0 ] in ('development' ,'testing' ,'production' ):
441- if self .scm [(args [0 ])] != getpass .getuser ():
442- print ("Current user " + os .getlogin ()+ " : Permission denied" )
443- sys .exit (127 )
383+ # if self.scm[(args[0])] != getpass.getuser():
384+ # print("Current user "+os.getlogin()+" : Permission denied")
385+ # sys.exit(127)
444386 if args .__len__ () == 2 :
445387 self .stage = args [0 ]
446388 self .domain = args [1 ]
0 commit comments