def test_copyfile(tmp_path): print("Testing utils.copyfile") from sregistry.utils import copyfile, write_file original = str(tmp_path / 'location1.txt') dest = str(tmp_path / 'location2.txt') print(original) print(dest) write_file(original, "CONTENT IN FILE") copyfile(original, dest) assert os.path.exists(original) assert os.path.exists(dest)
def test_write_read_files(tmp_path): '''test_write_read_files will test the functions write_file and read_file ''' print("Testing utils.write_file...") from sregistry.utils import write_file tmpfile = str(tmp_path / 'written_file.txt') assert not os.path.exists(tmpfile) write_file(tmpfile, "hello!") assert os.path.exists(tmpfile) print("Testing utils.read_file...") from sregistry.utils import read_file content = read_file(tmpfile)[0] assert content == "hello!"
def write_temp_recipe(recipe): '''write a temporary recipe file, given some recipe text for building. Parameters ========== recipe: the text from the interface to write ''' if recipe not in ['', None]: # Temporary name for recipe tmp = '/tmp/Singularity.%s'% next(tempfile._get_candidate_names()) recipe = write_file(tmp, recipe) return recipe
if os.path.exists(docker_file): continue # Now look for the Dockerfile url = "https://hub.docker.com/r/%s/~/dockerfile/" %(container) response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') text = soup.select("span[class^=Dockerfile]") if len(text) > 0: text = str(text[0]).replace('\n','<br>') dockerfile = html2text.html2text(text) # Check for missing dockerfile if len(dockerfile.replace('\n','')) == 0: dockerfile = None # If we have something, write it! if dockerfile is not None: print('Result for %s!' %(container)) # Create the output directory, if doesn't exist for outdir in [letter_dir, collection_dir, output_dir]: if not os.path.exists(outdir): os.mkdir(outdir) # Dockerfile is text file if dockerfile is not None: write_file(docker_file, dockerfile)
url = "https://hub.docker.com/r/%s/dockerfile/" % (container) print('url: %s' % (url)) response = requests.get(url) if response.status_code == 200: print('response.status_code: %s' % (response.status_code)) if url == "https://hub.docker.com/r/aaronshaf/dynamodb-admin/dockerfile/": print('response.text: %s' % (response.text)) soup = BeautifulSoup(response.text, 'html.parser') text = soup.select("code[class^=hljs]") print('text: %s' % (text)) if len(text) > 0: text = str(text[0]).replace('\n', '<br>') dockerfile = html2text.html2text(text) print('dockerfile: %s' % (dockerfile)) # Check for missing dockerfile if len(dockerfile.replace('\n', '')) == 0: dockerfile = None print('dockerfile: %s' % (dockerfile)) # If we have something, write it! if dockerfile is not None: print('Result for %s!' % (container)) # Create the output directory, if doesn't exist for outdir in [letter_dir, collection_dir, output_dir]: if not os.path.exists(outdir): os.mkdir(outdir) # Dockerfile is text file if dockerfile is not None: write_file(docker_file, dockerfile)