-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsBuild.py
174 lines (125 loc) · 5.2 KB
/
jenkinsBuild.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import os,shutil
from Utils import *
class jenkinsBuild:
def __init__(self, location, buildType,productType, integrationLocation = None):
self.location = location
self.buildNumber = ''
self.product_type = productType
self.builds_folder_name = self.product_type + '_Builds'
# if buildType == 'Stable':
self.archive_file = buildType + '_Archive.tgz'
self.folder_name = buildType + '_Builds'
self.tmpFolder = os.path.join(self.location,self.builds_folder_name,self.folder_name,'tmp')
self.Type = buildType
self.folder_build_type_path = os.path.join(self.location,self.builds_folder_name,self.folder_name)
# if buildType == 'Dev':
# self.archive_file = 'Dev_Archive.tgz'
# self.tmpFolder = self.location + 'Joota_Builds/Dev_Builds/tmp'
# self.Type = 'Dev'
# if buildType == 'Integration':
# self.archive_file = 'Specific_Archive.tgz'
# self.tmpFolder = self.location + 'Joota_Builds/Integration_Builds/tmp'
# self.Type = 'Integration'
def stableMoveAndExtract(self):
import tarfile
buildPath = os.path.join( self.folder_build_type_path,self.Type)
#Delete Any pre exisitng tmp folders
if os.path.exists(self.tmpFolder):
#delete new folder as you already have the build
shutil.rmtree(self.tmpFolder, ignore_errors=True)
else:
pass
if os.path.exists(os.path.join(self.location,self.archive_file)):
#Make Stable folder to put archive in
os.makedirs( self.tmpFolder);
#Move the .tgz to the new folder
shutil.move(self.location + self.archive_file, (self.tmpFolder))
#Change to the directory
os.chdir(self.tmpFolder)
#open the .tgz file
self.tfile = tarfile.open(self.archive_file)
#extract all
self.tfile.extractall()
#close the operation
self.tfile.close()
#Get the build number from the plist in the extracted Joota app in order to rename the folder
self.buildNumber = self.getBuildNumber()
newFolderPath = buildPath + '_' + self.buildNumber
if self.checkIfExists(newFolderPath):
pass
else:
# #Move back into the folder directory so we can rename it to that of the build number
os.chdir(self.location)
#Rename the folder from stable to stable_buildName
os.rename(self.tmpFolder , newFolderPath)
licenseObject = Utils(self.location)
licenseObject.createLicense(self.buildNumber)
# print 'Unpacked your build'
else:
# #If the file does not exist in your downloads then print out this message on the Gui
# print("No compressed file with the name \" Archive.tgz \" in your downloads directory...No action taken ")
pass
return self.buildNumber
def integrationMoveAndExtract(self,filePath,folderName):
compressionType = filePath[-4:]
buildPath = os.path.join(self.location, self.builds_folder_name, 'Integration_Builds')
self.fileName = os.path.basename(filePath)
self.newFolderPath = os.path.join(buildPath,folderName)
#Make sure the folder to be created does not exist and if it does check if there is a .ds_store in it, then get rid of that.
if os.path.exists(self.newFolderPath):
if len(self.newFolderPath) >0:
emptyFolder = os.listdir(self.newFolderPath)
if len(emptyFolder) == 0:
shutil.rmtree(self.newFolderPath, ignore_errors=True)
if len(emptyFolder) == 1 and emptyFolder[0] == '.DS_Store':
shutil.rmtree(self.newFolderPath, ignore_errors=True)
else:
pass
else:
pass
else:
pass
#Make Stable folder to put archive in
os.makedirs( self.newFolderPath );
shutil.move(filePath, (self.newFolderPath))
#Change to the directory
os.chdir(self.newFolderPath )
if compressionType == '.zip':
subprocess.call(['unzip', self.fileName])
if compressionType == '.tgz':
import tarfile
self.file = tarfile.open(self.fileName)
#extract all
self.file.extractall()
#close the operation
self.file.close()
def checkIfExists(self,newFolderPath):
#If the folder already exists (this program has been run on this day) then it will not create a new folder.
if os.path.exists(newFolderPath):
tmp_file_path = os.path.join(self.tmpFolder,self.archive_file)
#Move the archive out of the location so it doesn't get deleted
shutil.move(tmp_file_path, self.location)
#delete new folder as you already have the build
shutil.rmtree(self.tmpFolder, ignore_errors=True)
# os.remove(self.tmpFolder)
# print("You already have this build extracted in the correct place .... make sure that you're using the correct Archive.tgz")
return True
else:
return False
def getBuildNumber(self):
import plistlib
'''
Reads the PList from the Joota build to determine the build number
if darwin.....
'''
# Reads the plist build file an stores it in a dict
self.my_plist = plistlib.readPlist(self.folder_build_type_path + '/tmp/joota.app/Contents/info.plist')
# Searches through the dict for the CFBundleShortVersionString entry
self.buildString = self.my_plist["CFBundleShortVersionString"]
# Slices the line to the build number and removes the final character and stores it in the buildNumber variable
self.buildNumber = self.buildString[4:-1]
# print ('new folder build name is', self.buildNumber)
return self.buildNumber
if __name__ == "__main__":
Stable = jenkinsBuild()
Stable.retrieveFromJenkins()