magento插件打包工具(支持windows和linux)

使用方法:

1,下载packages.py文件,并且把该文件放在项目根目录下。比如:x2322.就放在/var/www/x2322/下面

 

2,执行命令

python packages.py 生成的文件名 包名 插件名 插件路径(1或2.1代表community,2代表local。默认是local下)

例如:打包Faarao_Colorpick插件 并保存到colorpick目录。

如果Faarao_Colorpick插件是放在app/code/local下面的,就这样:

python packages.py colorpick faarao colorpick 2

如果Faarao_Colorpick插件是放在app/code/community下面的,就这样:

python packages.py colorpick faarao colorpick 1
注意:

有可能模板和layout路径存放的名字不是按照插件名来的,所有会有漏掉。到时候自己再加进去。

现在window和linux平台都能直接用了(有bug的话记得找我)

文件代码:

packages.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#Filename : packages.py
# -*- coding: UTF-8 -*-
import os
import time
import sys
import shutil
import platform
copyFileCounts = 0
class magentoZip:
def __init__(self, target_dir, plusDir, plusName, modelName , newZipName ,type):
global opsystem
self.source = None
self.target_dir = target_dir
self.plusDir = plusDir
self.plusName = plusName[0].upper() + plusName[1:]
self.modelName = modelName[0].upper() + modelName[1:]
self.newZipName = newZipName
self.type = type
target = target_dir + newZipName
if os.path.isfile(target):
os.remove(target)
def exeZipFile(self):
#source = [r'D:\Users\array.h', r'D:\Users\arrayrc.h', r'D:\Users\test_for_poly.cpp', r'D:\Users\test.cpp']
# source = self.source
target_dir = self.target_dir
sourceDir = target_dir + self.newZipName
print sourceDir
if not os.path.exists(target_dir):
os.mkdir(target_dir)
#filename = time.strftime('%Y%m%d%H%M%S', time.localtime()) + '.zip'
filename = self.newZipName + '.zip'
# for i in source:
# print 'dir = ', i
target = target_dir + filename
if os.path.isfile(target):
os.remove(target)
#ep1 从名称中排除基本目录
zip_command = "rar a -r -ep1 %s %s " % (target, sourceDir + '\*')

print zip_command

if os.system(zip_command) == 0:
print 'Successful backup to', target
else :
print os.system(zip_command)
print 'backup FAILED'
def tarZipFile(self):
target_dir = self.target_dir
sourceDir = self.newZipName
print sourceDir
if not os.path.exists(target_dir):
os.mkdir(target_dir)
#filename = time.strftime('%Y%m%d%H%M%S', time.localtime()) + '.zip'
filename = self.newZipName + '.tar'
# for i in source:
# print 'dir = ', i
#target = target_dir + filename
if os.path.isfile(filename):
os.remove(filename)

os.system ("tar -cvf %s %s" % (filename, sourceDir))

if os.path.isfile (filename):
print 'Successful backup to', filename
else :
print 'backup FAILED'

def makeDirLinux(self):
print self.modelName

# os._exit()
if(self.type == '1'):
communityLocal = 'community/'
elif(self.type == '2'):
communityLocal = 'local/'
else:
raise Exception("no select type !")
os._exit('no select type')
sourceDir = self.plusDir + "/app/code/" + communityLocal + self.plusName + '/' + self.modelName
target_dir = self.target_dir + self.newZipName
print sourceDir
print opsystem
if os.path.isdir(target_dir):
shutil.rmtree(target_dir)
if os.path.isdir(sourceDir):
#creatDirs(target_dir, 'app', 2, self.plusName, self.modelName)
targetDir = target_dir + "/app/code/" + communityLocal + self.plusName + '/' + self.modelName
if not os.path.exists(targetDir):
os.makedirs(targetDir)
copyFiles(sourceDir, targetDir)
#Modules
etcSourceFile = self.plusDir + "/app/etc/modules/" + self.plusName + '_' +self.modelName +'.xml'
etcTargetDir = target_dir + "/app/etc/modules/"
copyFile(etcSourceFile,etcTargetDir)

#adminhtml layout
adminLayoutSourceFile = self.plusDir + "/app/design/adminhtml/default/default/layout/" + self.plusName.lower() + '_' + self.modelName[0].lower() + self.modelName[1:] +'.xml'
adminLayoutTargetDir = target_dir + '/app/design/adminhtml/default/default/layout/'

copyFile(adminLayoutSourceFile,adminLayoutTargetDir)

#adminhtml local en_US
adminLocalSourceFile = self.plusDir + '/app/design/adminhtml/default/default/locale/en_US/' + self.modelName[0].lower() + self.modelName[1:] +'.csv'
adminLocalTargetDir = target_dir + '/app/design/adminhtml/default/default/locale/en_US/'
copyFile(adminLocalSourceFile,adminLocalTargetDir)

#adminhtml template
adminTplSourceDir = self.plusDir + '/app/design/adminhtml/default/default/template/' + self.modelName[0].lower() + self.modelName[1:]
adminTplTargetDir = target_dir + '/app/design/adminhtml/default/default/template/' + self.modelName[0].lower() + self.modelName[1:]
#os._exit(0)
copyFiles(adminTplSourceDir, adminTplTargetDir)

#frontend base default layout
frontBaseLayoutSourceFile = self.plusDir + "/app/design/frontend/base/default/layout/" + self.plusName.lower() + '_' + self.modelName[0].lower() + self.modelName[1:] +'.xml'
frontBaseLayoutTargetFile = target_dir + "/app/design/frontend/base/default/layout/"
copyFile(frontBaseLayoutSourceFile,frontBaseLayoutTargetFile)

#frontend base default template
frontendBaseTplSourceDir = self.plusDir + '/app/design/frontend/base/default/template/' + self.modelName[0].lower() + self.modelName[1:]
frontendBaseTplTargetDir = target_dir + '/app/design/frontend/base/default/template/' + self.modelName[0].lower() + self.modelName[1:]
#os._exit(0)
copyFiles(frontendBaseTplSourceDir, frontendBaseTplTargetDir)

#frontend base default locale
frontBaseLocaleSourceFile = self.plusDir + "/app/design/frontend/base/default/locale/en_US/" + self.modelName[0].lower() + self.modelName[1:] +'.csv'
frontBaseLocaleTargetFile = target_dir + "/app/design/frontend/base/default/locale/en_US/"
copyFile(frontBaseLocaleSourceFile,frontBaseLocaleTargetFile)

#
#frontend default default layout
frontDefaultLayoutSourceFile = self.plusDir + "/app/design/frontend/default/default/layout/" + self.modelName[0].lower() + self.modelName[1:] +'.xml'
frontDefaultLayoutTargetFile = target_dir + "/app/design/frontend/default/default/layout/"
copyFile(frontDefaultLayoutSourceFile,frontDefaultLayoutTargetFile)

#frontend default default template
frontDefaultTplSourceDir = self.plusDir + '/app/design/frontend/default/default/template/' + self.modelName[0].lower() + self.modelName[1:]
frontDefaultTplTargetDir = target_dir + '/app/design/frontend/default/default/template/' + self.modelName[0].lower() + self.modelName[1:]
#os._exit(0)
copyFiles(frontDefaultTplSourceDir, frontDefaultTplTargetDir)

#frontend default default locale
frontDefaultLocaleSourceFile = self.plusDir + "/app/design/frontend/default/default/locale/en_US/" + self.modelName[0].lower() + self.modelName[1:] +'.csv'
frontDefaultLocaleTargetFile = target_dir + "/app/design/frontend/default/default/locale/en_US/"
copyFile(frontDefaultLocaleSourceFile,frontDefaultLocaleTargetFile)

else:
raise Exception("app is None")
#js
JsourceDir = self.plusDir + "/js/" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(JsourceDir):
#creatDirs(target_dir, 'js', 2, self.plusName, self.modelName)
Jtarget_dir = target_dir + '/js/' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(JsourceDir, Jtarget_dir)

else:
JsourceOtherDir = self.plusDir + "/js/" + self.plusName
if os.path.isdir(JsourceOtherDir):
Jtarget_dir = target_dir + '/js/' + self.plusName
copyFiles(JsourceDir, Jtarget_dir)
print "js is None"
#media
#MsourceDir = self.plusDir + "/media/" + self.modelName[0].lower() + self.modelName[1:]

#if os.path.isdir(MsourceDir):
#Mtarget_dir = target_dir + '/media/' + self.modelName[0].lower() + self.modelName[1:]
#copyFiles(MsourceDir, Mtarget_dir)
#else:
#print "media is None"
#lib
LsourceDir = self.plusDir + "/lib/" + self.modelName[0].lower() + self.modelName[1:]

if os.path.isdir(LsourceDir):
Ltarget_dir = target_dir + '/lib/' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(LsourceDir, Ltarget_dir)
else:
print "lib is None"
#skin
#admin base
AbaseSourceDir = self.plusDir + "/skin/adminhtml/base/default/" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(AbaseSourceDir):
Abasetarget_dir = target_dir + '/skin/adminhtml/base/default/' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(AbaseSourceDir, Abasetarget_dir)

#admin default
AdefaultSourceDir = self.plusDir + "/skin/adminhtml/default/default/" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(AdefaultSourceDir):
Adefaulttarget_dir = target_dir + '/skin/adminhtml/default/default/' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(AdefaultSourceDir, Adefaulttarget_dir)
#frontend base
FbaseSourceDir = self.plusDir + "/skin/frontend/base/default/" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(FbaseSourceDir):
Fbasetarget_dir = target_dir + '/skin/frontend/base/default/' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(FbaseSourceDir, Fbasetarget_dir)
#frontend default
FdefaultSourceDir = self.plusDir + "/skin/default/default/default/" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(FdefaultSourceDir):
Fdefaulttarget_dir = target_dir + '/skin/default/default/default/' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(FdefaultSourceDir, Fdefaulttarget_dir)

def makeDirWindows(self):
print self.type

# os._exit()
if(self.type == '1'):
communityLocal = 'community\\'
elif(self.type == '2'):
communityLocal = 'local\\'
else:
raise Exception("no select type !")
os._exit('no select type')
sourceDir = self.plusDir + r"\app\code\\" + communityLocal + self.plusName + r'\\' + self.modelName
target_dir = self.target_dir + self.newZipName
print target_dir
print opsystem
if os.path.isdir(target_dir):
shutil.rmtree(target_dir)
if os.path.isdir(sourceDir):
#creatDirs(target_dir, 'app', 2, self.plusName, self.modelName)
targetDir = target_dir + r"\app\code\\" + communityLocal + self.plusName + r'\\' + self.modelName
copyFiles(sourceDir, targetDir)
#Modules
etcSourceFile = self.plusDir + "\\app\\etc\\modules\\" + self.plusName + '_' +self.modelName +'.xml'
etcTargetDir = target_dir + "\\app\\etc\\modules\\"
copyFile(etcSourceFile,etcTargetDir)

#adminhtml layout
adminLayoutSourceFile = self.plusDir + r"\app\design\adminhtml\default\default\layout\\" + self.plusName + '_' +self.modelName +'.xml'
adminLayoutTargetDir = target_dir + r'\app\design\adminhtml\default\default\layout\\'
copyFile(adminLayoutSourceFile,adminLayoutTargetDir)

#adminhtml local en_US
adminLocalSourceFile = self.plusDir + r'\app\design\adminhtml\default\default\locale\en_US\\' + self.modelName[0].lower() + self.modelName[1:] +'.csv'
adminLocalTargetDir = target_dir + r'\app\design\adminhtml\default\default\locale\en_US\\'
copyFile(adminLocalSourceFile,adminLocalTargetDir)

#adminhtml template
adminTplSourceDir = self.plusDir + r'\app\design\adminhtml\default\default\template\\' + self.modelName[0].lower() + self.modelName[1:]
adminTplTargetDir = target_dir + r'\app\design\adminhtml\default\default\template\\' + self.modelName[0].lower() + self.modelName[1:]
#os._exit(0)
copyFiles(adminTplSourceDir, adminTplTargetDir)

#frontend base default layout
frontBaseLayoutSourceFile = self.plusDir + r"\app\design\frontend\base\default\layout\\" + self.plusName + '_' +self.modelName +'.xml'
frontBaseLayoutTargetFile = target_dir + r"\app\design\frontend\base\default\layout\\"
copyFile(frontBaseLayoutSourceFile,frontBaseLayoutTargetFile)

#frontend base default template
frontendBaseTplSourceDir = self.plusDir + r'\app\design\frontend\base\default\template\\' + self.modelName[0].lower() + self.modelName[1:]
frontendBaseTplTargetDir = target_dir + r'\app\design\frontend\base\default\template\\' + self.modelName[0].lower() + self.modelName[1:]
#os._exit(0)
copyFiles(frontendBaseTplSourceDir, frontendBaseTplTargetDir)

#frontend base default locale
frontBaseLocaleSourceFile = self.plusDir + r"\app\design\frontend\base\default\locale\en_US\\" + self.modelName[0].lower() + self.modelName[1:] +'.csv'
frontBaseLocaleTargetFile = target_dir + r"\app\design\frontend\base\default\locale\en_US\\"
copyFile(frontBaseLocaleSourceFile,frontBaseLocaleTargetFile)

#
#frontend default default layout
frontDefaultLayoutSourceFile = self.plusDir + r"\app\design\frontend\default\default\layout\\" + self.plusName + '_' +self.modelName +'.xml'
frontDefaultLayoutTargetFile = target_dir + r"\app\design\frontend\default\default\layout\\"
copyFile(frontDefaultLayoutSourceFile,frontDefaultLayoutTargetFile)

#frontend default default template
frontDefaultTplSourceDir = self.plusDir + r'\app\design\frontend\default\default\template\\' + self.modelName[0].lower() + self.modelName[1:]
frontDefaultTplTargetDir = target_dir + r'\app\design\frontend\default\default\template\\' + self.modelName[0].lower() + self.modelName[1:]
#os._exit(0)
copyFiles(frontDefaultTplSourceDir, frontDefaultTplTargetDir)

#frontend default default locale
frontDefaultLocaleSourceFile = self.plusDir + r"\app\design\frontend\default\default\locale\en_US\\" + self.modelName[0].lower() + self.modelName[1:] +'.csv'
frontDefaultLocaleTargetFile = target_dir + r"\app\design\frontend\default\default\locale\en_US\\"
copyFile(frontDefaultLocaleSourceFile,frontDefaultLocaleTargetFile)

else:
raise Exception("app is None")
#js
JsourceDir = self.plusDir + r"\js\\" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(JsourceDir):
#creatDirs(target_dir, 'js', 2, self.plusName, self.modelName)
Jtarget_dir = target_dir + r'\js\\' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(JsourceDir, Jtarget_dir)
else:
print "js is None"
#media
MsourceDir = self.plusDir + r"\media\\" + self.modelName[0].lower() + self.modelName[1:]

if os.path.isdir(MsourceDir):
Mtarget_dir = target_dir + r'\media\\' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(MsourceDir, Mtarget_dir)
else:
print "media is None"

#lib
LsourceDir = self.plusDir + r"\lib\\" + self.modelName[0].lower() + self.modelName[1:]

if os.path.isdir(LsourceDir):
Ltarget_dir = target_dir + r'\lib\\' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(LsourceDir, Ltarget_dir)
else:
print "lib is None"
#skin
#admin base
AbaseSourceDir = self.plusDir + r"\skin\adminhtml\base\default\\" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(AbaseSourceDir):
Abasetarget_dir = target_dir + r'\skin\adminhtml\base\default\\' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(AbaseSourceDir, Abasetarget_dir)
#admin default
AdefaultSourceDir = self.plusDir + r"\skin\adminhtml\default\default\\" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(AdefaultSourceDir):
Adefaulttarget_dir = target_dir + r'\skin\adminhtml\default\default\\' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(AdefaultSourceDir, Adefaulttarget_dir)
#frontend base
FbaseSourceDir = self.plusDir + r"\skin\frontend\base\default\\" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(FbaseSourceDir):
Fbasetarget_dir = target_dir + r'\skin\frontend\base\default\\' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(FbaseSourceDir, Fbasetarget_dir)
#frontend default
FdefaultSourceDir = self.plusDir + r"\skin\default\default\default\\" + self.modelName[0].lower() + self.modelName[1:]
if os.path.isdir(FdefaultSourceDir):
Fdefaulttarget_dir = target_dir + r'\skin\default\default\default\\' + self.modelName[0].lower() + self.modelName[1:]
copyFiles(FdefaultSourceDir, Fdefaulttarget_dir)
# print floder_path
# file_list = []
# if floder_path is None:
# raise Exception("floder_path is None")
# for dirpath, dirnames, filenames in os.walk(floder_path):
# #print dirnames
# for name in filenames:
# file_list.append(dirpath + '\\' + name)
# self.source = file_list
# target_dir = 'D:\\zhz\\aa'
# if not os.path.exists(target_dir):
# os.mkdir(target_dir)
# print target_dir

def copyFiles(sourceDir, targetDir):
if os.path.isdir(sourceDir):
if not os.path.exists(targetDir):
os.makedirs(targetDir)

global copyFileCounts
print sourceDir
print copyFileCounts
print u"%s 当前处理文件夹%s已处理%s 个文件" % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), sourceDir, copyFileCounts)
for f in os.listdir(sourceDir):
sourceF = os.path.join(sourceDir, f)
targetF = os.path.join(targetDir, f)
if os.path.isfile(sourceF):
#创建目录
if not os.path.exists(targetDir):
os.makedirs(targetDir)
copyFileCounts += 1
#文件不存在,或者存在但是大小不同,覆盖
if not os.path.exists(targetF) or (os.path.exists(targetF) and (os.path.getsize(targetF) != os.path.getsize(sourceF))):
#2进制文件
if(opsystem == 'w'):
os.system ("copy %s %s" % (sourceF, targetF))
elif(opsystem == 'l'):
os.system ("cp %s %s" % (sourceF, targetF))
if os.path.isfile (targetF): print "Success"
#open(targetF, "wb").write(open(sourceF, "rb").read());
print u"%s %s 复制完毕" % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), targetF)
else:
print u"%s %s 已存在,不重复复制" % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), targetF)
if os.path.isdir(sourceF):
copyFiles(sourceF, targetF)

def copyFile(sourceFile, targetDir):
if os.path.isfile(sourceFile):
if not os.path.exists(targetDir):
os.makedirs(targetDir)
if(opsystem == 'w'):
os.system ("copy %s %s" % (sourceFile, targetDir))
elif(opsystem == 'l'):
os.system ("cp %s %s" % (sourceFile, targetDir))

def isset(v):
try:
type (eval(v))
except:
return 0
else:
return 1
if __name__ == '__main__':
#example: python zip.py faarao_colorpick faarao colorpick 2
if len(sys.argv) <4:
print ("Error ! Missing parameter !\r\n#example: python packages.py faarao_colorpick faarao colorpick 2(1为community,2为local)")
os._exit(0)
plusDir = os.getcwd()
sysstr = platform.system()
#plusDir = r'D:\wamp\www\17test.mage'
#插件名 如"faarao"
plusName = sys.argv[2]
#模块名 如'colorpick'
modelName = sys.argv[3]
#保存的文件名
newZipName = sys.argv[1]
if(sysstr == "Windows"):
target_dir = plusDir + r'\\'
opsystem = 'w'
elif(sysstr == "Linux"):
target_dir = plusDir + '/'
opsystem = 'l'
else:
raise Exception("this system not support!\n")
#类型,是读取community下的还是local。默认是local
#type = sys.argv[4]
if len(sys.argv)> 4:
type = sys.argv[4]
else:
type = '2'
print 'newZipName ' + newZipName
print 'plusName ' + plusName
print 'modelName ' + modelName
print 'type ' + type
magento = magentoZip(target_dir, plusDir, plusName, modelName , newZipName , type)
if(opsystem == 'w'):
magento.makeDirWindows()
magento.exeZipFile()
elif(opsystem == 'l'):
magento.makeDirLinux()
magento.tarZipFile()

#magento.test()

参考:http://www.cnblogs.com/hongten/archive/2013/07/28/hongten_python_upper_lower.html

坚持原创技术分享,您的支持将鼓励我继续创作!