-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbgen-symlnk.py
executable file
·63 lines (57 loc) · 2.43 KB
/
bbgen-symlnk.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
#!/usr/bin/python
'''
This program is free software; you can redistribute it and/or modify
it under the terms of the Revised BSD License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Revised BSD License for more details.
Copyright 2015 Game Maker 2k - https://github.com/GameMaker2k
Copyright 2015 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: bbgen-symlnk.py - Last Update: 2/20/2015 Ver. 1.0.5 RC 2 - Author: cooldude2k $
'''
from __future__ import absolute_import, division, print_function, unicode_literals, generators, with_statement, nested_scopes
import os
import sys
import re
import subprocess
bbexecname = "busybox"
prependfilename = False
prependexecname = bbexecname+"-"
appendfilename = False
appendexecname = "-"+bbexecname
if(len(sys.argv) == 1):
cmdargpath = os.path.realpath(os.getcwd())
if(len(sys.argv) > 1):
cmdargpath = sys.argv[1]
if(not os.path.exists(cmdargpath)):
cmdargpath = os.path.realpath(os.getcwd())
cmdargpath = os.path.realpath(cmdargpath)
if(not os.path.isdir(cmdargpath)):
cmdargpath = os.path.dirname(os.path.realpath(cmdargpath))
if(not os.path.exists(cmdargpath)):
cmdargpath = os.path.realpath(os.getcwd())
bbllocatp = subprocess.Popen(
['which', bbexecname], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
bbllocatout, bbllocaterr = bbllocatp.communicate()
bbllocatout = re.sub('\s+', ' ', bbllocatout).strip()
bblistp = subprocess.Popen([bbexecname, '--help'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmdout, cmderr = bblistp.communicate()
pattmatch = re.compile("Currently defined functions:(.*)", re.DOTALL)
bblist = re.sub('\s+', ' ', re.findall(pattmatch, cmdout)[0])
bblist = [x.strip() for x in bblist.split(',')]
bblisti = 0
bblistil = len(bblist)
while(bblisti < bblistil):
if(prependfilename == True):
bblist[bblisti] = prependexecname+bblist[bblisti]
if(appendfilename == True):
bblist[bblisti] = bblist[bblisti]+appendexecname
bbfilename = os.path.join(cmdargpath, bblist[bblisti])
if(os.path.exists(bbfilename)):
print("removed '"+bbfilename+"'")
os.remove(bbfilename)
print("'"+bbfilename+"' -> '"+bbllocatout+"'")
os.symlink(bbllocatout, bbfilename)
bblisti = bblisti + 1