Beispiel #1
0
    def __init__(self, alias, url):
        if hg.islocal(url.encode("utf-8")):
            url = p(url).abspath()
            # Force git to use an absolute path in the future
            remote_name = os.path.basename(sys.argv[0]).replace("git-remote-", "")
            cmd = ["git", "config", "remote.%s.url" % alias, "%s::%s" % (remote_name, url)]
            subprocess.call(cmd)

        # use hash of URL as unique identifier in various places.
        # this has the advantage over 'alias' that it stays constant
        # when the user does a "git remote rename old new".
        if hg_version() >= "4.0.1":
            d = digester(["md5", "sha1"])
            d.update(url.encode("utf-8"))
            self.uuid = d["sha1"]
        else:
            self.uuid = sha1(url.encode("utf-8")).hexdigest()

        gitdir = p(os.environ["GIT_DIR"].decode("utf-8"))
        self.remotedir = gitdir.joinpath("hg", self.uuid)
        self.marks_git_path = self.remotedir.joinpath("marks-git")
        self.marks_hg_path = self.remotedir.joinpath("marks-hg")
        self.marks = HGMarks(self.marks_hg_path)
        self.git_marks = GitMarks(self.marks_git_path)
        self.parsed_refs = {}
        self.blob_marks = {}
        self.branches = {}
        self.bookmarks = {}

        self.prefix = "refs/hg/%s" % alias
        self.alias = alias
        self.url = url
        self.build_repo(url)
Beispiel #2
0
    def __init__(self, alias, url):
        if hg.islocal(url.encode('utf-8')):
            url = p(url).abspath()
            # Force git to use an absolute path in the future
            cmd = ['git', 'config', 'remote.%s.url' % alias, "gitifyhg::%s" % url]
            subprocess.call(cmd)

        # use hash of URL as unique identifier in various places.
        # this has the advantage over 'alias' that it stays constant
        # when the user does a "git remote rename old new".
        self.uuid = sha1(url.encode('utf-8')).hexdigest()

        gitdir = p(os.environ['GIT_DIR'].decode('utf-8'))
        self.remotedir = gitdir.joinpath('hg', self.uuid)
        self.marks_git_path = self.remotedir.joinpath('marks-git')
        self.marks = HGMarks(self.remotedir.joinpath('marks-hg'))
        self.parsed_refs = {}
        self.blob_marks = {}
        self.branches = {}
        self.bookmarks = {}

        self.prefix = 'refs/hg/%s' % alias
        self.alias = alias
        self.url = url
        self.build_repo(url)
Beispiel #3
0
    def __init__(self, alias, url):
        if hg.islocal(url.encode('utf-8')):
            url = p(url).abspath()
            # Force git to use an absolute path in the future
            remote_name = os.path.basename(sys.argv[0]).replace(
                "git-remote-", "")
            cmd = [
                'git', 'config',
                'remote.%s.url' % alias,
                "%s::%s" % (remote_name, url)
            ]
            subprocess.call(cmd)

        # use hash of URL as unique identifier in various places.
        # this has the advantage over 'alias' that it stays constant
        # when the user does a "git remote rename old new".
        self.uuid = sha1(url.encode('utf-8')).hexdigest()

        gitdir = p(os.environ['GIT_DIR'].decode('utf-8'))
        self.remotedir = gitdir.joinpath('hg', self.uuid)
        self.marks_git_path = self.remotedir.joinpath('marks-git')
        self.marks_hg_path = self.remotedir.joinpath('marks-hg')
        self.marks = HGMarks(self.marks_hg_path)
        self.git_marks = GitMarks(self.marks_git_path)
        self.parsed_refs = {}
        self.blob_marks = {}
        self.branches = {}
        self.bookmarks = {}

        self.prefix = 'refs/hg/%s' % alias
        self.alias = alias
        self.url = url
        self.build_repo(url)
Beispiel #4
0
def test_clone_replace_file_by_dir(git_dir, hg_repo):
    sh.cd(hg_repo)
    make_hg_commit("b", filename="dir_or_file")
    sh.hg.rm("dir_or_file")
    sh.mkdir("dir_or_file")
    make_hg_commit("c", filename="dir_or_file/test_file")

    git_repo = clone_repo(git_dir, hg_repo)
    sh.cd(git_repo)

    assert p('dir_or_file').isdir()
    assert p('dir_or_file/test_file').exists()
Beispiel #5
0
def test_clone_replace_symlink_by_file(git_dir, hg_repo):
    sh.cd(hg_repo)
    sh.ln("-s", "test_file", "link_or_file")
    sh.hg.add("link_or_file")
    sh.hg.commit(message="b")
    sh.hg.rm("link_or_file")
    make_hg_commit("c", filename="link_or_file")

    git_repo = clone_repo(git_dir, hg_repo)
    sh.cd(git_repo)

    assert p('link_or_file').isfile()
    assert not p('link_or_file').islink()
Beispiel #6
0
def test_clone_replace_dir_by_symlink(git_dir, hg_repo):
    sh.cd(hg_repo)
    sh.mkdir("dir_or_link")
    make_hg_commit("b", filename="dir_or_link/test_file")
    sh.hg.rm("dir_or_link/test_file")
    sh.ln("-s", "test_file", "dir_or_link")
    sh.hg.add("dir_or_link")
    sh.hg.commit(message="c")

    git_repo = clone_repo(git_dir, hg_repo)
    sh.cd(git_repo)

    assert p('dir_or_link').isfile()
    assert p('dir_or_link').islink()
Beispiel #7
0
    def handle(self, *args, **options):
        # make sure we're at project root
        chdir_dmd()

        self.json_folder = options.get('json_folder')

        logger.info("Importing Entities from JSON files from `{}`"
                    .format(self.json_folder))

        if not p(self.json_folder).isdir():
            logger.error("JSON folder `{}` is not a directory."
                         .format(self.json_folder))

        for level in range(5):
            self.enforced_level = level

            for fpath in os.listdir(self.json_folder):
                if not fpath.endswith('.json'):
                    continue

                # import entity
                eid = fpath[:-5]
                self.import_entity(eid)

        self.enforced_level = None
Beispiel #8
0
def test_unicode_path(tmpdir, git_dir, monkeypatch):
    monkeypatch.setenv('LANG', 'en_US.utf8')
    tmpdir = p(tmpdir.strpath).abspath()
    hg_base = tmpdir.joinpath(u'hg\u2020base')  # an hg repo to clone from
    hg_base.mkdir()
    sh.cd(hg_base)
    write_to_test_file(u'\u2020\n'.encode('utf-8'), u'\u2020')
    sh.hg.init()
    sh.hg.add(u'\u2020')
    sh.hg.commit(message=u"\u2020")
    sh.cd('..')

    sh.cd(git_dir)
    sh.git.clone("gitifyhg::" + hg_base, _err=sys.stderr)
    git_repo = git_dir.joinpath(u'hg\u2020base')
    sh.cd(git_repo)
    assert_git_messages([u"\u2020"])

    write_to_test_file(u'\u2020\n'.encode('utf-8'), u'\u2020')
    sh.git.add(u'\u2020')
    sh.git.commit(message=u"\u2020")
    sh.git.push()
    sh.cd(hg_base)
    sh.hg.update()
    assert_hg_count(2)

    write_to_test_file(u'\u2020\u2015'.encode('utf-8'), u'\u2020\u2015')
    sh.hg.add(u'\u2020\u2015')
    sh.hg.commit(message=u"\u2015")
    sh.cd(git_repo)
    sh.git.pull()
    assert_git_messages([u'\u2015', u"\u2020", u"\u2020"])
Beispiel #9
0
def setup_pkg(virtualenv, pkg_dir, options, test=True, indent_txt='',
              deps=True):
    """
    Sets up a package in the given virtualenv

    Parameters
    ----------
    virtualenv : `str`
        virtulenv base dir
    pkg_dir : `str`
        package checkout dir
    options : `optparse.Options`
        command-line options
    test : `bool`
        True/False will install test packages
    deps : `bool`
        True/False will install dependencies
    """
    from path import path as p
    get_log().info("%s Setting up package in %s" % (indent_txt, pkg_dir))
    if getattr(options, 'no_action', False):
        return
    python = p(virtualenv) / 'bin' / 'python'
    cmd = [python, 'setup.py']
    if options.verbose:
        cmd.append('-v')
    cmd.append('develop')
    if not test:
        cmd.append('--no-test')
    if getattr(options, 'prefer_final', False):
        cmd.append('--prefer-final')
    if not deps:
        cmd.append('--no-deps')
    with chdir(pkg_dir):
        run(cmd, capture_stdout=not options.verbose)
Beispiel #10
0
    def handle(self, *args, **options):
        # make sure we're at project root
        chdir_dmd()

        self.json_folder = options.get('json_folder')

        logger.info("Importing Entities from JSON files from `{}`".format(
            self.json_folder))

        if not p(self.json_folder).isdir():
            logger.error("JSON folder `{}` is not a directory.".format(
                self.json_folder))

        for level in range(5):
            self.enforced_level = level

            for fpath in os.listdir(self.json_folder):
                if not fpath.endswith('.json'):
                    continue

                # import entity
                eid = fpath[:-5]
                self.import_entity(eid)

        self.enforced_level = None
Beispiel #11
0
def format(s):
    "Recursively formats string using the `env` dict."
    is_path = isinstance(s, p)
    prev = None
    while prev != s:
        prev = s
        s = s.format(**env)
    return p(s) if is_path else s
Beispiel #12
0
def expand(s):
    "Recursively expands given string using the `env` dict."
    is_path = isinstance(s, p)
    prev = None
    while prev != s:
        prev = s
        s = s % env
    return p(s) if is_path else s
Beispiel #13
0
def format(s):
    "Recursively formats string using the `env` dict."
    is_path = isinstance(s, p)
    prev = None
    while prev != s:
        prev = s
        s = s.format(**env)
    return p(s) if is_path else s
def cleanup():
    dirname = Path.cwd()
    seven_days_ago = time.time() - 7 * 86400
    base = p(os.path.join(dirname, Path('csv/')))

    for file in base.walkfiles():
        if file.mtime < seven_days_ago:
            file.remove()
Beispiel #15
0
def make_hg_commit(message, filename="test_file", user="******"):
    """Assuming we are in a mercurial repository, write the message to the
    filename and commit it."""
    add = not p(filename).exists()
    write_to_test_file(message, filename)
    if add:
        sh.hg.add(filename)
    sh.hg.commit(message=message, user=user)
Beispiel #16
0
def expand(s):
    "Recursively expands given string using the `env` dict."
    is_path = isinstance(s, p)
    prev = None
    while prev != s:
        prev = s
        s = s % env
    return p(s) if is_path else s
Beispiel #17
0
def test_sym_link(git_dir, hg_repo):
    sh.cd(hg_repo)
    write_to_test_file('b')
    sh.hg.add('test_file')
    sh.hg.commit(message="b")
    sh.ln('-s', 'test_file', 'linked')
    sh.hg.add('linked')
    sh.hg.commit(message="c")
    git_repo = clone_repo(git_dir, hg_repo)
    sh.cd(git_repo)
    assert p('linked').islink()
    sh.ln('-s', 'test_file', 'second_link')
    sh.git.add('second_link')
    sh.git.commit(message="d")
    sh.git.push()
    sh.cd(hg_repo)
    sh.hg.update()
    assert p('second_link').islink()
Beispiel #18
0
def test_clone_remove_file(git_dir, hg_repo):
    sh.cd(hg_repo)
    make_hg_commit("b")
    sh.hg.rm("test_file")
    sh.hg.commit(message="c")

    git_repo = clone_repo(git_dir, hg_repo)
    sh.cd(git_repo)

    assert not p('a').exists()
Beispiel #19
0
    def _create_folder_tree(service_name, dest_filename):
        # create recursing folders on destination
        walked_folders = []
        for folder in p(dest_filename).splitall()[:-1]:
            if not folder:
                continue

            walked_folders.append(folder)
            path = os.path.join(*walked_folders)

            _create_folder(service_name, path)
Beispiel #20
0
def write_to_test_file(message, filename="test_file"):
    """Append the message to the 'test_file' file in the current working
    directory or filename if it was passed. This is normally done to stage a
    commit in hg or git.

    :param message: Something to be appended to the test file. Use \\n
        judiciously.
    :param filename: A filename to commit to. If unsupplied, test_file
        will be updated."""
    with p(filename).open("a") as file:
        file.write(message)
Beispiel #21
0
def git_dir(tmpdir):
    """Fixture that creates a subdirectory in the tmpdir to hold the git clone.

    :param tmpdir: the temporary directory for the current test
    :return: a py.path inside the test's temporary directory that is an empty
        but existing directory."""
    os.environ["DEBUG_GITIFYHG"] = "on"

    tmpdir = p(tmpdir.strpath).abspath()
    git_dir = tmpdir.joinpath("git_dir")
    git_dir.mkdir()
    return git_dir
Beispiel #22
0
def test_empty_repo(tmpdir):
    tmpdir = p(tmpdir.strpath).abspath()
    hg_base = tmpdir.joinpath('hg_base')
    hg_base.mkdir()
    sh.cd(hg_base)
    sh.hg.init()

    sh.cd(tmpdir)
    sh.git.clone("gitifyhg::" + hg_base, "git_clone")

    sh.cd("git_clone")
    assert "Initial commit" in sh.git.status().stdout
    make_git_commit("a")

    sh.git.push("origin", "master")

    sh.cd(hg_base)
    assert_hg_count(1)
    sh.hg.update()
    with open(hg_base.joinpath('test_file')) as file:
        assert file.read() == "a"
Beispiel #23
0
def hg_repo(tmpdir):
    '''Fixture that creates an hg repository in a temporary directory
    gitifyhg can then be tested by cloaning that repo.

    Also sets the DEBUG_GITIFYHG environment variable.

    :param tmpdir: A temporary directory for the current test
    :return: a py.path inside the test's temporary directory that contains
        an initialized hg repository with a single commit'''
    os.environ['DEBUG_GITIFYHG'] = "on"
    os.environ['GIT_PAGER'] = 'cat'
    os.environ['HGPLAIN'] = '1'
    tmpdir = p(tmpdir.strpath).abspath()
    hg_base = tmpdir.joinpath('hg_base')  # an hg repo to clone from
    hg_base.mkdir()
    sh.cd(hg_base)
    write_to_test_file('a\n')
    sh.hg.init()
    sh.hg.add('test_file')
    sh.hg.commit(message="a")
    sh.cd('..')

    return hg_base
Beispiel #24
0
def hg_repo(tmpdir):
    """Fixture that creates an hg repository in a temporary directory
    gitifyhg can then be tested by cloaning that repo.

    Also sets the DEBUG_GITIFYHG environment variable.

    :param tmpdir: A temporary directory for the current test
    :return: a py.path inside the test's temporary directory that contains
        an initialized hg repository with a single commit"""
    os.environ["DEBUG_GITIFYHG"] = "on"
    os.environ["GIT_PAGER"] = "cat"
    os.environ["HGRCPATH"] = ""  # So extensions like pager don't interfere
    tmpdir = p(tmpdir.strpath).abspath()
    hg_base = tmpdir.joinpath("hg_base")  # an hg repo to clone from
    hg_base.mkdir()
    sh.cd(hg_base)
    write_to_test_file("a\n")
    sh.hg.init()
    sh.hg.add("test_file")
    sh.hg.commit(message="a")
    sh.cd("..")

    return hg_base
Beispiel #25
0
    
    browserify_js      = 'vendor/browserify.js',
    work_browserify_js = '%(work_dir)s/%(browserify_js)s',
    
    vendor_search_dirs = ['static', 'var', '%(work_dir)s'],
    vendor_bundle      = '%(work_dir)s/vendor/vendor-bundle.min.js',
    app_bundle         = '%(work_dir)s/js/limn/app-bundle.js',
))

env_paths = (
    'dist', 'local_tmp', 'work_dir', 
    'browserify_js', 'work_browserify_js',
    'vendor_bundle', 'app_bundle',
)
for k in env_paths:
    env[k] = p(env[k])

env.vendor_search_dirs = [ expand(p(vd)) for vd in env.vendor_search_dirs ]
env.app_bundle_min     = p(env.app_bundle.replace('.js', '.min.js'))


### Setup Staging Environments

# Envs aren't declared with @task in the stages module so that we can
# decorate them here and have them show up at the top level.
import stages

for name in stages.STAGE_NAMES:
    globals()[name] = task(getattr(stages, name))

Beispiel #26
0
from path import path as p

path = p(1)

print '-' * 50
print path.g_hash_index()
print path.g_word_wide()
Beispiel #27
0
from path import path as p


path = p(1)

print '-'*50
print path.g_hash_index()
print path.g_word_wide()