a
This commit is contained in:
parent
c599ed4560
commit
be660c91e8
9 changed files with 160 additions and 46 deletions
32
app/abk.py
Normal file
32
app/abk.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import subprocess
|
||||
import os
|
||||
|
||||
from pipfile import Pipfile
|
||||
|
||||
|
||||
def globally_installed_py_packages():
|
||||
output = subprocess.check_output("pip list --format freeze".split(), env={})
|
||||
output = output.decode("utf-8")
|
||||
output = output.strip()
|
||||
global_packages = output.split("\n")
|
||||
return global_packages
|
||||
|
||||
|
||||
global_packages = globally_installed_py_packages()
|
||||
|
||||
p = Pipfile.load(filename="meowPip")
|
||||
content = ""
|
||||
with open("meowPip", "r") as f:
|
||||
content = f.read()
|
||||
|
||||
for pip_package in p.data["default"]:
|
||||
version = p.data["default"][pip_package]
|
||||
if version == "*":
|
||||
for package in global_packages:
|
||||
package = package.lower()
|
||||
if package.startswith(pip_package.lower()):
|
||||
substr = f'{pip_package} = "*"'
|
||||
content = content.replace(substr, package)
|
||||
|
||||
with open("meowPippy", "w") as f:
|
||||
f.write(content)
|
||||
|
|
@ -54,7 +54,7 @@ def setup(
|
|||
content = (
|
||||
f"AUTH_NAME={auth_name}\n"
|
||||
f"AUTH_SEED={auth_seed}\n"
|
||||
f"AUTH_REALM={auth_seed}\n"
|
||||
f"AUTH_REALM={auth_realm}\n"
|
||||
f"REALM_ALLOWED={list(realm_allowed)}\n"
|
||||
f"OTP_SERVER={otp_server}\n"
|
||||
f"ETCD_URL={etcd_url}\n"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import os
|
|||
from dataclasses import dataclass
|
||||
from abc import ABC
|
||||
from enum import Enum
|
||||
from pipfile import Pipfile
|
||||
|
||||
|
||||
class ResultType(Enum):
|
||||
|
|
@ -97,10 +98,39 @@ class VirtualenvOperation(object):
|
|||
else:
|
||||
return Result(output, ResultType.success)
|
||||
|
||||
|
||||
def globally_installed_py_packages():
|
||||
output = subprocess.check_output("pip list --format freeze".split(), env={})
|
||||
output = output.decode("utf-8")
|
||||
output = output.strip()
|
||||
global_packages = output.split("\n")
|
||||
return global_packages
|
||||
|
||||
|
||||
class PipenvOperation(object):
|
||||
@staticmethod
|
||||
def create(path=".", site_packages=False):
|
||||
if site_packages:
|
||||
global_packages = globally_installed_py_packages()
|
||||
|
||||
p = Pipfile.load(filename=os.path.join(path, "Pipfile"))
|
||||
content = ""
|
||||
with open(os.path.join(path, "Pipfile"), "r") as f:
|
||||
content = f.read()
|
||||
|
||||
for pip_package in p.data["default"]:
|
||||
version = p.data["default"][pip_package]
|
||||
if version == "*":
|
||||
for package in global_packages:
|
||||
package = package.lower()
|
||||
if package.startswith(pip_package.lower()):
|
||||
substr = f'{pip_package} = "*"'
|
||||
content = content.replace(substr, package)
|
||||
|
||||
with open(os.path.join(path, "Pipfile"), "w") as f:
|
||||
f.write(content)
|
||||
|
||||
|
||||
command = f"pipenv --site-packages --python 3"
|
||||
else:
|
||||
command = "pipenv --python 3"
|
||||
|
|
@ -118,7 +148,7 @@ class PipenvOperation(object):
|
|||
else:
|
||||
with open(os.path.join(path, "requirements.txt"), "w") as f:
|
||||
subprocess.Popen("pipenv run pip freeze".split(), cwd=path, stdout=f)
|
||||
command = f"pip install -r requirements.txt"
|
||||
command = f"pipenv run pip install -r requirements.txt"
|
||||
try:
|
||||
output = subprocess.check_output(command.split(), cwd=path)
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
|
@ -126,7 +156,6 @@ class PipenvOperation(object):
|
|||
else:
|
||||
return Result(output, ResultType.success)
|
||||
|
||||
|
||||
class FileOperation(object):
|
||||
@staticmethod
|
||||
def write(path, content, mode="w"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue