-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
63 lines (46 loc) · 2.24 KB
/
setup.py
File metadata and controls
63 lines (46 loc) · 2.24 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
from shutil import copyfile
import os
import stat
import urllib.request
import re
class Setup:
def __init__(self):
self.devkitPath = os.path.expanduser("~")+"/.devkit";
self.binaryPath = "/usr/local/bin/devkit";
""" Execute the setup """
def run(self):
print("Installing the devkit...");
# copy the installer to the local binary folder
copyfile('./installer.py', self.binaryPath);
# get current permissions of the devkit
st = os.stat(self.binaryPath);
# change permission to executable
os.chmod(self.binaryPath, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH);
# If the devkit folder does not exists, create it
if not os.path.exists(self.devkitPath):
print("Creating the devkit folder...");
os.makedirs(self.devkitPath);
print("Moving the default files to the devkit folder...");
# Copy the ruleset and the commit hook to the .devkit folder
copyfile('./codesniffer/ruleset.xml', self.devkitPath+"/ruleset.xml");
copyfile('./codesniffer/pre-commit', self.devkitPath+"/pre-commit");
# Read the content of the config file
file = open('./codesniffer/config', 'r+');
content = file.read();
# Replace the placeholders with the .devkit location
content = re.sub(r'(\[\[ BINPATH \]\])', self.devkitPath+"/phpcs.phar", content);
content = re.sub(r'(\[\[ RULESETPATH \]\])', self.devkitPath+"/ruleset.xml", content);
# Create a new config file inside the .devkit folder and insert the data
file = open(self.devkitPath+'/config', 'w');
file.write(content);
file.close();
print("Downloading the phpcs.phar and moving it to the devkit folder...");
# Downlaod phpcs and move it to the .devkit folder
urllib.request.urlretrieve("https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar", self.devkitPath+"/phpcs.phar");
# Make sure the phpcs file is executable
st = os.stat(self.devkitPath+"/phpcs.phar");
os.chmod(self.devkitPath+"/phpcs.phar", st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH);
print("");
print("Installation complete!");
setup = Setup();
setup.run();