Skip to content

Commit

Permalink
tools: move gap_exec to utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Apr 1, 2022
1 parent aa60ace commit 6f296a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
17 changes: 3 additions & 14 deletions tools/scan_for_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
import json
import os
import requests
import subprocess
from os.path import join
from multiprocessing.pool import ThreadPool

from download_packages import download_archive

import utils
from utils import notice, error, warning, all_packages, metadata, metadata_fname, sha256, archive_name

from typing import Dict, Optional, Tuple
from typing import Dict, Optional

archive_dir = "_archives"
pkginfos_dir = "_pkginfos"
Expand All @@ -54,17 +54,6 @@ def download_pkg_info(pkg_name: str) -> Optional[bytes]:
return response.content


def gap_exec(commands: str, args="") -> Tuple[int, bytes]:
with subprocess.Popen(
"gap -A -b --quitonbreak -q " + args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
shell=True,
) as GAP:
out, err = GAP.communicate(input=commands.encode('utf-8'))
return GAP.returncode, out


def scan_for_one_update(pkginfos_dir: str, pkg_name: str) -> Optional[str]:
pkg_json = metadata(pkg_name)
try:
Expand Down Expand Up @@ -98,7 +87,7 @@ def scan_for_updates(pkginfos_dir = pkginfos_dir, disable_threads = False):
def output_json(updated_pkgs, pkginfos_dir = pkginfos_dir):
dir_of_this_file = os.path.dirname(os.path.realpath(__file__))
str = '", "'.join(updated_pkgs)
result, _ = gap_exec(
result, _ = utils.gap_exec(
'OutputJson(["{}"], "{}");'.format(str, pkginfos_dir),
args="{}/pkginfo_to_json.g".format(dir_of_this_file),
)
Expand Down
3 changes: 1 addition & 2 deletions tools/tests/test_scan_for_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@

from scan_for_updates import (
download_pkg_info,
gap_exec,
main,
output_json,
scan_for_one_update,
scan_for_updates,
sha256,
)

from utils import gap_exec, sha256

@pytest.fixture
def ensure_in_tests_dir():
Expand Down
16 changes: 14 additions & 2 deletions tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import hashlib
import json
import os
import sys
import requests
import subprocess
import sys
import tempfile

from os.path import join

from typing import NoReturn
from typing import NoReturn, Tuple

# print notices in green
def notice(msg):
Expand Down Expand Up @@ -128,3 +129,14 @@ def symlink(target, link_name, overwrite=False):
if os.path.islink(temp_link_name):
os.remove(temp_link_name)
raise


def gap_exec(commands: str, args: str = "") -> Tuple[int, bytes]:
with subprocess.Popen(
"gap -A -b --quitonbreak -q " + args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
shell=True,
) as GAP:
out, err = GAP.communicate(input=commands.encode('utf-8'))
return GAP.returncode, out
5 changes: 3 additions & 2 deletions tools/validate_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
from tempfile import TemporaryDirectory

from download_packages import download_archive
from scan_for_updates import download_pkg_info, gap_exec
from scan_for_updates import download_pkg_info

import utils
from utils import notice, warning, error, normalize_pkg_name, archive_name, metadata, sha256


Expand Down Expand Up @@ -105,7 +106,7 @@ def main(pkgs):
pkgdir = join(tempdir, validate_tarball(archive_fname))
shutil.unpack_archive(archive_fname, tempdir)
validate_package(archive_fname, pkgdir, pkg_name)
result, _ = gap_exec(
result, _ = utils.gap_exec(
"ValidatePackagesArchive(\"{}\", \"{}\");".format(pkgdir, pkg_name),
args="{}/validate_package.g".format(dir_of_this_file),
)
Expand Down

0 comments on commit 6f296a3

Please sign in to comment.