Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
new_args += ['--mflags=--noextract', ]
print(color_line('\n => ', 10) + ' '.join(new_args))
intercepted: InterceptSysOutput
with InterceptSysOutput(
capture_stderr=capture_stderr,
capture_stdout=capture_stdout
) as _intercepted:
try:
# re-parse args:
sys.argv = new_args
CachedArgs.args = None # pylint:disable=protected-access
MakePkgCommand._cmd = None # pylint:disable=protected-access
parse_args()
# monkey-patch to force always uncolored output:
CachedArgs.args.color = 'never' # type: ignore # pylint:disable=protected-access
# finally run pikaur's mainloop
main()
except FakeExit:
pass
intercepted = _intercepted
PackageDB.discard_local_cache()
PackageDB.discard_repo_cache()
return CmdResult(
returncode=intercepted.returncode,
stdout=intercepted.stdout_text,
def communicate(self, _input=None, _timeout=None) -> Tuple[bytes, bytes]:
# pylint:disable=import-outside-toplevel
from .args import parse_args
if parse_args().verbose:
from .pprint import print_stderr, color_line
if self.args != get_sudo_refresh_command():
print_stderr(
color_line('=> ', 14) +
' '.join(str(arg) for arg in self.args)
)
stdout, stderr = super().communicate(_input, _timeout)
self.stdout_text = stdout.decode('utf-8') if stdout else None
self.stderr_text = stderr.decode('utf-8') if stderr else None
return stdout, stderr
def cli_print_upgradeable() -> None:
args = parse_args()
updates: List[InstallInfo] = []
if not args.repo:
aur_updates, _not_found_aur_pkgs = find_aur_updates()
updates += aur_updates
if not args.aur:
updates += find_repo_upgradeable()
if not updates:
return
if args.quiet:
print_stdout('\n'.join([
pkg_update.name for pkg_update in updates
]))
else:
print_stdout(pretty_format_upgradeable(
updates,
print_repo=PikaurConfig().sync.AlwaysShowPkgOrigin.get_bool()
def color_enabled() -> bool:
args = parse_args()
if args.color == 'never':
return False
if args.color == 'always' or (sys.stderr.isatty() and sys.stdout.isatty()):
return True
return False
repo_packages: Iterable[AnyPackage],
aur_packages: Iterable[AnyPackage],
local_pkgs_versions: Dict[str, str],
enumerated=False,
) -> List[AnyPackage]:
def get_sort_key(pkg: AnyPackage) -> float:
if (
isinstance(pkg, AURPackageInfo) and
isinstance(pkg.numvotes, int) and
isinstance(pkg.popularity, float)
):
return (pkg.numvotes + 1) * (pkg.popularity + 1)
return 1
args = parse_args()
local_pkgs_names = local_pkgs_versions.keys()
sorted_packages: List[AnyPackage] = list(repo_packages) + list(sorted(
aur_packages,
key=get_sort_key,
reverse=True
))
enumerated_packages = list(enumerate(sorted_packages))
if PikaurConfig().ui.ReverseSearchSorting.get_bool():
enumerated_packages = list(reversed(enumerated_packages))
for pkg_idx, package in enumerated_packages:
# @TODO: return only packages for the current architecture
idx = ''
if enumerated:
idx = bold_line(f'{pkg_idx+1}) ')
def package_search_thread_repo(query: str) -> List[pyalpm.Package]:
args = parse_args()
if query:
result = PackageDB.search_repo(
query, names_only=args.namesonly
)
else:
result = PackageDB.get_repo_list(quiet=True)
if not args.quiet:
sys.stderr.write('#')
return result
def ask_to_continue(text: str = None, default_yes: bool = True) -> bool:
args = parse_args()
if text is None:
text = _('Do you want to proceed?')
if args.noconfirm:
print_stderr('{} {}'.format(
text,
_("[Y]es (--noconfirm)") if default_yes else _("[N]o (--noconfirm)")
))
return default_yes
prompt = text + (' [%s/%s] ' % (Y_UP, N) if default_yes else ' [%s/%s] ' % (Y, N_UP))
answers = Y_UP + N if default_yes else Y + N_UP
answer = get_input(prompt, answers)
return (answer == Y) or (default_yes and answer == '')
proc = PikspectPopen(
cmd,
print_output=print_output,
default_questions=default_questions,
**kwargs
)
extra_questions = extra_questions or {}
if conflicts:
extra_questions[YesNo.ANSWER_Y] = (
extra_questions.get(YesNo.ANSWER_Y, []) + format_conflicts(conflicts)
)
if extra_questions:
proc.add_answers(extra_questions)
if parse_args().verbose:
print_stderr(color_line('=> ', 14) + ' '.join(cmd))
proc.run()
return proc
def package_search_thread_aur(queries: List[str]) -> Dict[str, List[Any]]:
args = parse_args()
result = {}
if queries:
use_as_filters: List[str] = []
with ThreadPool() as pool:
requests = {}
for query in queries:
requests[query] = pool.apply_async(aur_rpc_search_name_desc, (query, ))
pool.close()
for query, request in requests.items():
try:
result[query] = request.get()
except AURError as exc:
if exc.error == "Too many package results.":
print_error(
_("AUR: Too many package results for '{query}'").format(
query=query