This repository was archived by the owner on May 11, 2025. It is now read-only.
forked from processing/processing-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperm-parse.py
More file actions
36 lines (30 loc) · 1.19 KB
/
Copy pathperm-parse.py
File metadata and controls
36 lines (30 loc) · 1.19 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
''' How to use
1. Go to https://developer.android.com/reference/android/Manifest.permission.html and select desired API level.
2. Save page as Webpage complete
3. Run parse.py filename
4. Use output to set the updated permissions listing in Permissions.java
'''
import sys, re
from BeautifulSoup import BeautifulSoup
filename = sys.argv[1]
data = open(filename,'r').read()
soup = BeautifulSoup(data)
table = soup.find('table', { 'id': 'constants', 'class' : 'responsive constants' })
entries = table.findAll('tr')
print(' static final String[] listing = {')
for entry in entries:
if not entry or not entry.attrs: continue
if 'absent' in entry.attrs[0][1]: continue
info = entry.find('td', {'width':'100%'})
if info:
name = info.find('code').find('a').contents[0]
pieces = []
for piece in info.find('p').contents:
piece_str = re.sub('\s+', ' ', str(piece)).strip()
if '<code>' in piece_str:
piece_str = piece.find('a').contents[0].strip();
pieces += [piece_str]
if name and pieces:
desc = ' '.join(pieces).strip().replace('"', '\\"')
print ' "' + name + '", "' + desc + '",'
print(' };')