Skip to content

Commit 8f34cf2

Browse files
authoredJul 7, 2021
Merge pull request #36 from rackerlabs/pleskbuddy_py3
git subrepo pull (merge) pleskbuddy
2 parents d636902 + 6c5c09b commit 8f34cf2

File tree

3 files changed

+129
-57
lines changed

3 files changed

+129
-57
lines changed
 

‎pleskbuddy/.gitrepo

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[subrepo]
77
remote = https://github.com/dsgnr/pleskbuddy.git
88
branch = master
9-
commit = 725b4d82c8acedc982660294506bad7fec752a2c
10-
parent = 7f0dcc3f5860a416b42ceeb0926ae7d94cedc4dd
9+
commit = 44c475bd9e2308126f8fc8ec6dd29c0286db49f1
10+
parent = 81c8281679783228392558ea78caa82aada554c6
1111
method = merge
12-
cmdver = 0.4.1
12+
cmdver = 0.4.3

‎pleskbuddy/pleskbuddy.py

+124-52
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,79 @@
1-
#!/bin/python
1+
#!/usr/bin/env python
22
# pleskbuddy.py created by Dan Hand
33

44
from __future__ import absolute_import, division, print_function
55

66
# Standard Library
77
import argparse
88
import sys
9-
from subprocess import call, PIPE, Popen
10-
from urllib2 import urlopen
9+
from subprocess import PIPE, Popen, call
1110

1211

13-
__version__ = '1.0.0'
12+
try:
13+
# Standard Library
14+
from urllib.request import urlopen
15+
except ImportError:
16+
# Third Party
17+
from urllib2 import urlopen
18+
19+
20+
__version__ = "2.0.0"
1421

1522

1623
def options():
1724
psa_parser = argparse.ArgumentParser()
18-
psa_parser.add_argument('-v', '--version', dest='show_version',
19-
action='store_true', help='Shows version information')
20-
psa_parser.add_argument('--sub-list', dest='subscription_list',
21-
action='store_true', help='Shows a list of subscriptions')
22-
psa_parser.add_argument('--info', dest='info',
23-
action='store_true', help='Shows a list of subscriptions')
24-
psa_parser.add_argument('--domain-list', dest='domain_list',
25-
action='store_true', help='Shows a list of domains with their IP addresses')
26-
psa_parser.add_argument('--list-components', dest='show_components',
27-
action='store_true', help='Creates a list of available components')
28-
psa_parser.add_argument('--install-component', dest='component_install', type=str,
29-
help='Allows installation of available component')
30-
psa_parser.add_argument('--php-handler', dest='php_handler',
31-
action='store_true', help='Displays a list of domains with their respective PHP handler')
25+
psa_parser.add_argument(
26+
"-v",
27+
"--version",
28+
dest="show_version",
29+
action="store_true",
30+
help="Shows version information",
31+
)
32+
psa_parser.add_argument(
33+
"--sub-list",
34+
dest="subscription_list",
35+
action="store_true",
36+
help="Shows a list of subscriptions",
37+
)
38+
psa_parser.add_argument(
39+
"--info", dest="info", action="store_true", help="Shows a list of subscriptions"
40+
)
41+
psa_parser.add_argument(
42+
"--domain-list",
43+
dest="domain_list",
44+
action="store_true",
45+
help="Shows a list of domains with their IP addresses",
46+
)
47+
psa_parser.add_argument(
48+
"--list-components",
49+
dest="show_components",
50+
action="store_true",
51+
help="Creates a list of available components",
52+
)
53+
psa_parser.add_argument(
54+
"--install-component",
55+
dest="component_install",
56+
type=str,
57+
help="Allows installation of available component",
58+
)
59+
psa_parser.add_argument(
60+
"--php-handler",
61+
dest="php_handler",
62+
action="store_true",
63+
help="Displays a list of domains with their respective PHP handler",
64+
)
3265
return psa_parser
3366

3467

3568
class Color(object):
36-
RED = '\033[31m\033[1m'
37-
GREEN = '\033[32m\033[1m'
38-
YELLOW = '\033[33m\033[1m'
39-
BLUE = '\033[34m\033[1m'
40-
MAGENTA = '\033[35m\033[1m'
41-
CYAN = '\033[36m\033[1m'
42-
WHITE = '\033[37m\033[1m'
43-
RESET = '\033[0m'
69+
RED = "\033[31m\033[1m"
70+
GREEN = "\033[32m\033[1m"
71+
YELLOW = "\033[33m\033[1m"
72+
BLUE = "\033[34m\033[1m"
73+
MAGENTA = "\033[35m\033[1m"
74+
CYAN = "\033[36m\033[1m"
75+
WHITE = "\033[37m\033[1m"
76+
RESET = "\033[0m"
4477

4578

4679
# Variables
@@ -49,69 +82,108 @@ class Color(object):
4982

5083

5184
def show_version():
52-
print(Color.CYAN + r'''
85+
print(
86+
Color.CYAN
87+
+ r"""
5388
_ _ _ _ _
5489
_ __ | | ___ ___| | _| |__ _ _ __| | __| |_ _
5590
| '_ \| |/ _ \/ __| |/ / '_ \| | | |/ _` |/ _` | | | |
5691
| |_) | | __/\__ \ <| |_) | |_| | (_| | (_| | |_| |
5792
| .__/|_|\___||___/_|\_\_.__/ \__,_|\__,_|\__,_|\__, |
5893
|_| |___/
5994
60-
version: %s ''' % (__version__), Color.RESET)
95+
version: %s """
96+
% (__version__),
97+
Color.RESET,
98+
)
6199

62100

63101
def info():
64-
domain_count = Popen('MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -sNe \
65-
"select count(*) from domains"', stdout=PIPE, shell=True).communicate()[0].strip()
66-
plesk_version = open('/usr/local/psa/version', "r").read().split()
67-
login_url = Popen('plesk login -relative-url', stdout=PIPE, shell=True).communicate()[0].strip()
68-
public_ip = urlopen('https://ipv4.icanhazip.com').read().strip()
69-
psa_info = (Color.MAGENTA + '==== Plesk Information ====\n' + Color.RESET +
70-
Color.MAGENTA + 'Login URL: ' + Color.RESET + 'https://{0}:8443{1}\n' + Color.MAGENTA +
71-
'Plesk version: ' + Color.RESET + '{2}\n' + Color.MAGENTA +
72-
'Domain Count: ' + Color.RESET + '{3}').format(public_ip, login_url, plesk_version[0], str(domain_count))
102+
domain_count = (
103+
Popen(
104+
'MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -sNe \
105+
"select count(*) from domains"',
106+
stdout=PIPE,
107+
shell=True,
108+
)
109+
.communicate()[0]
110+
.strip()
111+
.decode("utf-8")
112+
)
113+
plesk_version = open("/usr/local/psa/version", "r").read().split()[0]
114+
login_url = (
115+
Popen("plesk login -relative-url", stdout=PIPE, shell=True)
116+
.communicate()[0]
117+
.strip()
118+
.decode("utf-8")
119+
)
120+
public_ip = urlopen("https://ipv4.icanhazip.com").read().strip().decode("utf-8")
121+
psa_info = (
122+
Color.MAGENTA
123+
+ "==== Plesk Information ====\n"
124+
+ Color.RESET
125+
+ Color.MAGENTA
126+
+ "Login URL: "
127+
+ Color.RESET
128+
+ "https://{0}:8443{1}\n"
129+
+ Color.MAGENTA
130+
+ "Plesk version: "
131+
+ Color.RESET
132+
+ "{2}\n"
133+
+ Color.MAGENTA
134+
+ "Domain Count: "
135+
+ Color.RESET
136+
+ "{3}"
137+
).format(public_ip, login_url, plesk_version, str(domain_count))
73138
print(psa_info)
74139

75140

76141
def subscription_list():
77-
print(Color.MAGENTA + '==== Plesk Subscription List ====' + Color.RESET)
78-
subscription_list = 'plesk bin subscription --list'
142+
print(Color.MAGENTA + "==== Plesk Subscription List ====" + Color.RESET)
143+
subscription_list = "plesk bin subscription --list"
79144
call(subscription_list, shell=True)
80145

81146

82147
def domain_list():
83-
print(Color.MAGENTA + '==== Plesk Domain List ====' + Color.RESET)
84-
domain_list = 'MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -e"SELECT dom.id, dom.name, \
148+
print(Color.MAGENTA + "==== Plesk Domain List ====" + Color.RESET)
149+
domain_list = "MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -e\"SELECT dom.id, dom.name, \
85150
ia.ipAddressId, iad.ip_address FROM domains dom LEFT JOIN DomainServices d ON \
86-
(dom.id = d.dom_id AND d.type = \'web\') LEFT JOIN IpAddressesCollections ia ON \
87-
ia.ipCollectionId = d.ipCollectionId LEFT JOIN IP_Addresses iad ON iad.id = ia.ipAddressId"'
151+
(dom.id = d.dom_id AND d.type = 'web') LEFT JOIN IpAddressesCollections ia ON \
152+
ia.ipCollectionId = d.ipCollectionId LEFT JOIN IP_Addresses iad ON iad.id = ia.ipAddressId\""
88153
call(domain_list, shell=True)
89154

90155

91156
def show_components():
92-
print(Color.MAGENTA + '==== Plesk Component List ====' + Color.RESET)
93-
component_list = 'plesk installer --select-release-current --show-components'
157+
print(Color.MAGENTA + "==== Plesk Component List ====" + Color.RESET)
158+
component_list = "plesk installer --select-release-current --show-components"
94159
call(component_list, shell=True)
95160

96161

97162
def component_install():
98-
call(['plesk', 'installer', '--select-release-current',
99-
'--install-component', PSA_ARGS.component_install])
163+
call(
164+
[
165+
"plesk",
166+
"installer",
167+
"--select-release-current",
168+
"--install-component",
169+
PSA_ARGS.component_install,
170+
]
171+
)
100172

101173

102174
def php_handler():
103-
print(Color.MAGENTA + '==== Plesk domains and their PHP handler ====' + Color.RESET)
175+
print(Color.MAGENTA + "==== Plesk domains and their PHP handler ====" + Color.RESET)
104176
domains_with_php = 'plesk db "select d.name,h.php_handler_id from domains d join hosting h on h.dom_id=d.id"'
105177
call(domains_with_php, shell=True)
106178

107179

108180
def main():
109181
# Check if Plesk is installed
110182
try:
111-
_ = open('/usr/local/psa/version', 'r')
183+
_ = open("/usr/local/psa/version", "r")
112184
except IOError as ex:
113-
sys.exit('It doesn\'t look like Plesk is installed!')
114-
185+
sys.exit("It doesn't look like Plesk is installed!")
186+
115187
if PSA_ARGS.show_version:
116188
show_version()
117189
elif PSA_ARGS.subscription_list:
@@ -128,5 +200,5 @@ def main():
128200
info()
129201

130202

131-
if __name__ == '__main__':
203+
if __name__ == "__main__":
132204
main()

‎pleskbuddy/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pylint==1.9.4
2-
pycodestyle==2.6.0
1+
pylint==2.9.3
2+
pycodestyle==2.7.0

0 commit comments

Comments
 (0)
Failed to load comments.