-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
126 lines (102 loc) · 3.42 KB
/
setup.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
from setuptools.command.install import install
import shutil
import grp
import pwd
import sys
import os
class PermissionDenied(Exception):
pass
class InstallWrapper(install):
def run(self):
self._startup_check()
self._install_config()
self._install_data()
install.run(self)
def _fix_folder_perms(self, path):
if "SUDO_USER" in os.environ:
user = os.environ["SUDO_USER"]
else:
user = os.environ["USER"]
uid = pwd.getpwnam(user).pw_uid
gid = pwd.getpwnam(user).pw_gid
for root, dirs, files in os.walk(path):
os.chown(root, uid, gid)
for d in dirs:
dname = os.path.join(root, d)
os.chown(dname, uid, gid)
for f in files:
fname = os.path.join(root, f)
os.chown(fname, uid, gid)
def _get_user(self):
if "SUDO_USER" in os.environ:
user = os.environ["SUDO_USER"]
else:
user = os.environ["USER"]
return user
def _startup_check(self):
# Are you root ?
if os.geteuid() == 0:
return
# Are you in docker group ?
user_grps = [
g.gr_name for g in grp.getgrall() if os.environ["USER"] in g.gr_mem
]
if "docker" in user_grps:
return
# Now we might have a problem...
raise PermissionDenied(
"Current user will not have permisson to execute commands. Either install as root, or join docker group."
)
def _install_config(self):
user = self._get_user()
config_dir = f"/home/{user}/.config/rete"
if os.path.exists(f"{config_dir}/rete.yml"):
return
if not os.path.exists(config_dir):
shutil.copytree("config", config_dir)
self._fix_folder_perms(config_dir)
def _install_data(self):
user = self._get_user()
data_dir = f"/home/{user}/.local/share/rete"
if os.path.exists(f"{data_dir}/chrome.json"):
return
if not os.path.exists(data_dir):
shutil.copytree("data", data_dir)
self._fix_folder_perms(data_dir)
with open(os.path.join("rete", "VERSION"), "r", encoding="utf-8") as f:
version = f.read()
with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()
setup(
name="rete",
version=version,
description="",
license="GPLv3",
long_description=long_description,
author="retenet",
author_email="[email protected]",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 3",
"Operating System :: POSIX :: Linux",
"Environment :: Console",
],
keywords="browser",
packages=find_packages(exclude=["browsers", "contrib", "docs", "tests"]),
install_requires=[
"docker==4.4.0",
"elevate==0.1.3",
"jsonschema==3.2.0",
"PyYAML==5.3.1",
"rich==9.5.1"
],
extras_require={"dev": ["black==20.8b1", "ipython==7.19.0", "pytest==6.2.1"],},
entry_points={"console_scripts": ["rete = rete.cli:main",],},
include_package_data=True,
cmdclass={"install": InstallWrapper},
)