Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
with pytest.raises(base.UriError):
base.GenericSyncer('/', 'seriouslynotaprotocol://blah/')
syncer = base.GenericSyncer('/', f'tar+https://blah.tar.gz')
assert tar.tar_syncer is syncer.__class__
def test_uri_parse(self):
# external binary doesn't exist
with mock.patch('snakeoil.process.find_binary') as find_binary:
find_binary.side_effect = CommandNotFound('cvs')
with pytest.raises(base.SyncError):
cvs.cvs_syncer(
str(self.repo_path), "cvs+/bin/sh://foon.com/dar")
# fake that the external binary exists
with mock.patch('snakeoil.process.find_binary') as find_binary:
find_binary.return_value = 'cvs'
# nonexistent rsh
with mock.patch('pkgcore.sync.base.ExternalSyncer.require_binary') as require_binary:
require_binary.side_effect = base.MissingBinary('', 'rsh')
with pytest.raises(base.SyncError):
cvs.cvs_syncer(str(self.repo_path), "cvs+rsh://foon.com/dar")
o = cvs.cvs_syncer(str(self.repo_path), "cvs://dar:module")
assert o.uri == ":anoncvs:dar"
assert o.module == "module"
assert o.rsh == None
assert o.env["CVSROOT"] == ":anoncvs:dar"
o = cvs.cvs_syncer(str(self.repo_path), "cvs+pserver://dar:module")
assert o.uri == ":pserver:dar"
assert o.module == "module"
assert o.rsh == None
assert o.env["CVSROOT"] == ":pserver:dar"
with mock.patch('pkgcore.sync.base.ExternalSyncer.require_binary') as require_binary:
require_binary.return_value = '/bin/sh'
def test_uri_parse(self):
assert sqfs_syncer.parse_uri("sqfs+http://repo.lzo.sqfs") == "http://repo.lzo.sqfs"
# missing actual URI protocol
with pytest.raises(base.UriError):
sqfs_syncer.parse_uri("sqfs+://repo.lzo.sqfs")
# we don't yet support autodetection from URI suffixes
with pytest.raises(base.UriError):
sqfs_syncer.parse_uri("https://repo.lzo.sqfs")
o = sqfs_syncer("/tmp/foon", "sqfs+https://repo.lzo.sqfs")
assert o.uri == "https://repo.lzo.sqfs"
def test_uri_parse(self):
assert bzr.bzr_syncer.parse_uri("bzr+http://dar") == "http://dar"
with pytest.raises(base.UriError):
bzr.bzr_syncer.parse_uri("bzr://dar")
# external binary doesn't exist
with mock.patch('snakeoil.process.find_binary') as find_binary:
find_binary.side_effect = CommandNotFound('bzr')
with pytest.raises(base.SyncError):
bzr.bzr_syncer(str(self.repo_path), "bzr+http://foon.com/dar")
# fake that the external binary exists
with mock.patch('snakeoil.process.find_binary') as find_binary:
find_binary.return_value = 'bzr'
o = bzr.bzr_syncer(str(self.repo_path), "bzr+http://dar")
o.uri == "http://dar"
def test_missing_binary(self, find_binary):
find_binary.side_effect = CommandNotFound('foo')
with pytest.raises(base.MissingBinary):
base.ExternalSyncer(self.repo_path, 'http://dar')
def test_basedir_is_file_error(self, spawn, find_binary, tmp_path):
repo = tmp_path / "repo"
repo.touch()
syncer = git.git_syncer(str(repo), 'git://blah.git')
# basedir gets '/' appended by default and stat errors out
with pytest.raises(base.PathError) as excinfo:
syncer.sync()
# remove trailing slash from basedir and file check catches it instead
syncer.basedir = str(repo)
with pytest.raises(base.PathError) as excinfo:
syncer.sync()
assert "isn't a directory" in str(excinfo.value)
__all__ = ("cvs_syncer",)
import os
from pkgcore.sync import base
class cvs_syncer(base.VcsSyncer):
binary = "cvs"
supported_uris = (
('cvs+', 5),
('cvs://', 5),
)
@classmethod
def is_usable_on_filepath(cls, path):
cvs_path = os.path.join(path, "CVS")
if cls.disabled or not os.path.isdir(cvs_path):
return None
return (cls._rewrite_uri_from_stat(cvs_path, 'cvs://'),)
@classmethod
def _get_syncer(self, lazy=False):
singleton = object()
syncer = getattr(self.repo, '_syncer', singleton)
if syncer is singleton:
# raw repo's vs non-raw; drive down to the raw repo.
# see pkgcore.ebuild.repository for an example
syncer = getattr(self.repo, 'config', None)
syncer = getattr(syncer, '_syncer', None)
if not lazy and not isinstance(syncer, _sync_base.Syncer):
syncer = syncer.instantiate()
return syncer
import atexit
from functools import partial
import os
import subprocess
import shutil
import tempfile
import uuid
from snakeoil.osutils import ensure_dirs
from pkgcore.sync import base
from pkgcore.sync.http import http_syncer
class tar_syncer(http_syncer, base.ExternalSyncer):
binary = 'tar'
supported_uris = (
('tar+http://', 5),
('tar+https://', 5),
)
# TODO: support more of the less used file extensions
supported_protocols = ('http://', 'https://')
supported_exts = ('.tar.gz', '.tar.bz2', '.tar.xz')
@classmethod
def parse_uri(cls, raw_uri):
if raw_uri.startswith(("tar+http://", "tar+https://")):
raw_uri = raw_uri[4:]
__all__ = ("hg_syncer",)
import os
from pkgcore.sync import base
class hg_syncer(base.VcsSyncer):
binary = "hg"
supported_uris = (
('hg+', 5),
('mercurial+', 5),
)
@classmethod
def is_usable_on_filepath(cls, path):
hg_path = os.path.join(path, '.hg')
if cls.disabled or not os.path.isdir(hg_path):
return None
return (cls._rewrite_uri_from_stat(hg_path, 'hg+//'),)
@staticmethod