-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsBuild.py
99 lines (79 loc) · 3.09 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
import os
import shutil
class jenkinsBuild:
def __init__(self, location, fileName, folderPath, buildType,buildNumber, integrationLocation = None):
self.location = location
self.buildNumber = buildNumber
# self.product_type = productType
# self.builds_folder_name = self.product_type + '_Builds'
self.archive_file = fileName
self.file_location = os.path.join(self.location,fileName)
self.folder_name = buildType + '_Builds'
self.tmpFolder = os.path.join(folderPath,'tmp')
self.Type = buildType
self.folder_build_type_path = folderPath
def MoveAndExtract(self):
import tarfile
#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)
if os.path.exists(self.file_location):
#Make temp folder to put archive in
os.makedirs(self.tmpFolder);
#Move the .tgz to the new folder
shutil.move(self.file_location, 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()
newFolderPath = os.path.join(self.folder_build_type_path,self.buildNumber)
#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)
# 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 ")
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()
if __name__ == "__main__":
Stable = jenkinsBuild()
Stable.retrieveFromJenkins()