This repository was archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjarparse.py
More file actions
executable file
·40 lines (37 loc) · 1.45 KB
/
jarparse.py
File metadata and controls
executable file
·40 lines (37 loc) · 1.45 KB
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
#!/usr/bin/env python
from zipfile import ZipFile
from cStringIO import StringIO
import yaml
import sys
def find_plugin_yaml(dataobj):
'''
'''
yml = False
try:
# The first thing we are going to try to do is create a ZipFile
# object with the StringIO data that we have.
zfile = ZipFile(dataobj)
except:
print '[DEBUG] ZipFile Library Failed to Parse DataObject'
else:
# Before we start recursively jumping through hoops, lets first
# check to see if the plugin.yml exists at this level. If so, then
# just set the yaml variable. Otherwise we are gonna look for more
# zip and jar files and dig into them.
if 'plugin.yml' in zfile.namelist():
try:
yml = yaml.load(zfile.read('plugin.yml'))
except:
return False
else:
for filename in zfile.namelist():
if not yml and filename[-3:].lower() in ['zip', 'jar']:
print '[DEBUG] Found Zip/Jar file ' + filename
data = StringIO()
data.write(zfile.read(filename))
yml = find_plugin_yaml(data)
data.close()
zfile.close()
return yml
if __name__ == '__main__':
print yaml.dump(find_plugin_yaml(open(sys.argv[1], 'r')))