Skip to content

Commit 22ba053

Browse files
committed
upgrade
1 parent d2e33c3 commit 22ba053

File tree

10 files changed

+104
-94
lines changed

10 files changed

+104
-94
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ nosetests.xml
3636
.pydevproject
3737
/shell/*.bak
3838
MANIFEST
39+
MANIFEST.in

bin/deployment

Lines changed: 24 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -14,73 +14,16 @@ from datetime import datetime
1414
basedir=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1515

1616
try:
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
2021
except ImportError as err:
2122
print("Error: %s" %(err))
2223

2324
CONFIG_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+
##############################################
8427
class 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]

etc/deployment.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
[main]
1+
[scm]
22
;basedir=/usr/local
33
cfgdir=/srv/devops/etc
44
logdir=/srv/devops/log
55
logfile=deployment.log
66
pidfile=/tmp/oscm.pid
77

8-
[scm]
98
;Software Configuration Management Engineer
109
moderator=neo
1110
development=dev
1211
testing=testing
1312
production=neo
1413

15-
[node]
16-
logdir=/srv/devops/log
14+
[project]
15+
cfgdir=~
16+
logdir=~/log
1717
source=~/.repositories
1818
backup=~/.backup

library/git.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#-*- coding: utf-8 -*-
2+
import os, sys
3+
class Git():
4+
cmd = []
5+
def __init__(self, workspace = None, logging = None):
6+
self.logging = logging
7+
self.workspace = workspace
8+
def option(self, opt):
9+
if opt:
10+
self.opt = opt
11+
def clone(self, uri):
12+
if self.workspace :
13+
self.cmd.append('clone '+ uri +' '+ self.workspace)
14+
return(self)
15+
def pull(self):
16+
if self.workspace :
17+
os.chdir(self.workspace)
18+
self.cmd.append('pull --progress')
19+
return(self)
20+
def reset(self):
21+
self.cmd.append('reset HEAD --hard')
22+
return(self)
23+
def branch(self, branchname=None, op=None):
24+
os.chdir(self.workspace)
25+
if branchname :
26+
if op == 'delete':
27+
self.cmd.append('branch -D '+branchname)
28+
elif op == 'new':
29+
self.cmd.append('checkout -fb '+branchname+' --')
30+
else:
31+
self.cmd.append('reset HEAD --hard')
32+
self.cmd.append('fetch origin')
33+
self.cmd.append('checkout -f '+branchname)
34+
else:
35+
self.cmd.append('branch')
36+
return(self)
37+
def merge(self, branchname):
38+
self.cmd.append('merge '+branchname)
39+
return(self)
40+
def tag(self, tagname):
41+
os.chdir(self.workspace)
42+
self.cmd.append('tag ' + tagname)
43+
return(self)
44+
def checkout(self, revision=None):
45+
os.chdir(self.workspace)
46+
if revision :
47+
self.cmd.append('checkout -f '+revision)
48+
return(self)
49+
def debug(self):
50+
cmd = ''
51+
for line in self.cmd:
52+
cmd += 'git ' + line + '; '
53+
return(cmd)
54+
def execute(self):
55+
for line in self.cmd:
56+
os.system('git '+ line)
57+
self.logging.debug('git '+ line)
58+
self.cmd = []
59+
print("-")

library/whiptail.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#-*- coding: utf-8 -*-
12
import os,subprocess
23

34
class Whiptail():

setup.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
# pass
1515

1616
setup(
17-
name='oscm',
17+
name='devops',
1818
version=__version__,
19-
description="Collection of useful functions and classes",
19+
description="DevOps of useful deployment and automation",
2020
long_description=readme + '\n\n' + changes,
21-
keywords='oscm',
21+
keywords='devops',
2222
author=__author__,
2323
author_email='[email protected]',
2424
url='http://netkiller.github.io',
@@ -34,7 +34,7 @@
3434
'License :: OSI Approved :: BSD License',
3535
'Operating System :: OS Independent',
3636
'Programming Language :: Python',
37-
'Programming Language :: Python :: 3.3',
37+
'Programming Language :: Python :: 3.4',
3838
],
3939
package_dir={ '': 'library' },
4040
packages=[
@@ -44,16 +44,17 @@
4444
'bin/deployment',
4545
'bin/backup',
4646
'bin/mysqlshell',
47-
'bin/auditlog'
47+
'bin/auditlog',
48+
'bin/gitsync'
4849
],
4950
data_files = [
5051
('etc', ['etc/deployment.cfg']),
5152
('etc', ['etc/task.cfg']),
5253
('etc', ['etc/schedule.cfg']),
5354
('log', ['log/deployment.log']),
54-
('project/testing', ['project/testing/example.com.ini']),
55-
('project/config/testing', ['project/config/testing/www.example.com.ini']),
56-
('project/exclude/testing', ['project/exclude/testing/www.example.com.lst'])
55+
('example/testing', ['example/testing/example.com.ini']),
56+
('example/config/testing', ['example/config/testing/www.example.com.ini']),
57+
('example/exclude/testing', ['example/exclude/testing/www.example.com.lst'])
5758

5859
]
5960
)
File renamed without changes.
File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[bg7nyt]
2+
repository=https://github.com/netkiller/phalcon.git
3+
remote= 192.168.6.1
4+
destination=x64.me/bg7nyt.x64.me
5+
logfile=/tmp/bg7nyt.x64.me.log
6+
delete=Y

0 commit comments

Comments
 (0)