seafobj/ci/utils.py
feiniks adca4803bf
Add objwrapper pkg (#82)
* Add objwrapper pkg

* Add objwrapper test

* Add boto3

* Add oss2

* Modify func name

* Modify envs name

* Use secrets

* Add oss2

* Use read obj raw

* Use random repo_id

* Use ObjectIterator to list oss objects

* Use iterator to list s3 objects

* Modify func and parameters name

---------

Co-authored-by: 杨赫然 <heran.yang@seafile.com>
2024-10-26 16:37:48 +08:00

50 lines
1.1 KiB
Python

import os
import logging
from subprocess import PIPE, CalledProcessError, Popen
import sys
import termcolor
logger = logging.getLogger(__name__)
def setup_logging():
kw = {
"format": "[%(asctime)s][%(module)s]: %(message)s",
"datefmt": "%m/%d/%Y %H:%M:%S",
"level": logging.DEBUG,
"stream": sys.stdout,
}
logging.basicConfig(**kw)
logging.getLogger("requests.packages.urllib3.connectionpool").setLevel(
logging.WARNING
)
def shell(cmd, inputdata=None, wait=True, **kw):
info('calling "%s" in %s', cmd, kw.get("cwd", os.getcwd()))
kw["shell"] = not isinstance(cmd, list)
kw["stdin"] = PIPE if inputdata else None
p = Popen(cmd, **kw)
if inputdata:
p.communicate(inputdata)
if wait:
p.wait()
if p.returncode:
raise CalledProcessError(p.returncode, cmd)
else:
return p
def info(fmt, *a):
logger.info(green(fmt), *a)
def green(s):
return _color(s, "green")
def _color(s, color):
return s if not os.isatty(sys.stdout.fileno()) else termcolor.colored(str(s), color)