-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder.py
More file actions
executable file
·88 lines (80 loc) · 3.38 KB
/
builder.py
File metadata and controls
executable file
·88 lines (80 loc) · 3.38 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
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
#! /usr/bin/env python3
import re
import os
import shutil
import argparse
import fileinput
import sys
import fnmatch
class RedextensionWizard:
""""create utility for joomla"""
def __init__(self, component, destination):
self.base = "."
self.component = component
self.destination = destination
def export(self):
print('exporting ', self.component, ' to ', self.destination)
# git export
os.system('git checkout-index -a -f --prefix=' + self.destination + '/')
self._replace_filename()
self._replace_content()
os.chdir(self.destination)
os.system('git init')
os.system('git submodule add git@github.com:redCOMPONENT-COM/redCORE.git build/redCORE')
os.system('cd extensions/components/com_' + self.component + '/libraries/' + self.component + ' && composer dump-autoload')
os.system('cd build && npm install')
print('done')
def _replace_filename(self):
for path, subdirs, files in os.walk(self.destination):
for fname in files:
if('redeventcart' in fname):
os.rename(os.path.join(path, fname), os.path.join(path,
fname.replace('redeventcart', self.component)))
for path, subdirs, files in os.walk(self.destination, topdown=False):
for fname in subdirs:
if('redeventcart' in fname):
os.rename(os.path.join(path, fname), os.path.join(path,
fname.replace('redeventcart', self.component)))
def _replace_content(self):
for path, dirs, files in os.walk(os.path.abspath(self.destination)):
for filename in files:
if filename.lower().endswith(('.jpg', '.png', '.phar')):
continue
filepath = os.path.join(path, filename)
print(filepath)
with open(filepath) as f:
s = f.read()
s = self._case_sensitive_replace(s, 'redeventcart', self.component)
with open(filepath, "w") as f:
f.write(s)
def _case_sensitive_replace(self, string, old, new):
""" replace occurrences of old with new, within string
replacements will match the case of the text it replaces
"""
def repl(match):
current = match.group()
result = ''
all_upper=True
for i,c in enumerate(current):
if i >= len(new):
break
if c.isupper():
result += new[i].upper()
else:
result += new[i].lower()
all_upper=False
#append any remaining characters from new
if all_upper:
result += new[i+1:].upper()
else:
result += new[i+1:].lower()
return result
regex = re.compile(re.escape(old), re.I)
return regex.sub(repl, string)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Create redCORE extension')
parser.add_argument('-c', '--component', required=True, help='the component name')
parser.add_argument('-d', '--destination', required=True, help='the folder where to export the component repo')
args = parser.parse_args()
x = RedextensionWizard(args.component, args.destination)
x.export()