73 lines
1.6 KiB
Python
73 lines
1.6 KiB
Python
import os
|
|
import sys
|
|
|
|
import modulus.process
|
|
|
|
def conan_remote(context):
|
|
return str(context.tooling["remote"]["name"])
|
|
|
|
def conan_remote_url(context):
|
|
return context.tooling["remote"]["url"]
|
|
|
|
def conan_user():
|
|
return os.environ.get("CONAN_USER")
|
|
|
|
def conan_token():
|
|
return os.environ.get("CONAN_TOKEN")
|
|
|
|
def conan_credentials():
|
|
return conan_user(), conan_token()
|
|
|
|
def require_conan_credentials(operation):
|
|
user, token = conan_credentials()
|
|
if bool(user) != bool(token):
|
|
print("CONAN_USER and CONAN_TOKEN must either both be set or both be unset", file=sys.stderr)
|
|
return None
|
|
if not user or not token:
|
|
print(f"CONAN_USER and CONAN_TOKEN are required to {operation}", file=sys.stderr)
|
|
return None
|
|
return user, token
|
|
|
|
def configure_conan_remote(context, authenticate=False):
|
|
remote = conan_remote(context)
|
|
credentials = require_conan_credentials("upload Conan packages") if authenticate else None
|
|
if authenticate and credentials is None:
|
|
return 1
|
|
status = modulus.process.run(
|
|
context,
|
|
[
|
|
"conan",
|
|
"remote",
|
|
"add",
|
|
"-f",
|
|
remote,
|
|
conan_remote_url(context),
|
|
],
|
|
)
|
|
if status != 0:
|
|
return status
|
|
if not authenticate:
|
|
return modulus.process.run(context, ["conan", "remote", "logout", remote])
|
|
user, token = credentials
|
|
return modulus.process.run(
|
|
context,
|
|
[
|
|
"conan",
|
|
"remote",
|
|
"login",
|
|
remote,
|
|
user,
|
|
"-p",
|
|
token,
|
|
],
|
|
display_command=[
|
|
"conan",
|
|
"remote",
|
|
"login",
|
|
remote,
|
|
user,
|
|
"-p",
|
|
"<hidden>",
|
|
],
|
|
)
|