Ejemplo n.º 1
0
def initialize_git_repository() -> None:
    """Prepare the git repository."""
    print("    * Initializing the project git repository")

    try:
        git.init()
        git.remote(
            "add",
            "origin",
            "[email protected]:{{ cookiecutter.github_user }}/"
            "{{ cookiecutter.project_slug }}.git",
        )
        git.add(".")
        git.commit("-m", "feat: create initial project structure")
        git.checkout("-b", "gh-pages")
        git.checkout("-b", "feat/initial_iteration")

        print("    * Pushing initial changes to master")
        git.push("--force", "--set-upstream", "origin", "master")
        git.push("--force", "--set-upstream", "origin", "gh-pages")
        git.push("--force", "--set-upstream", "origin",
                 "feat/initial_iteration")
        git.push("--force")
    except sh.ErrorReturnCode as error:
        print("There was an error creating the Git repository.")
        print(str(error.stderr, "utf8"))
        sys.exit(1)
Ejemplo n.º 2
0
def migrate_to_git():
    users = parse_users()
    git_repo = arguments['<git_repo>']

    if not os.path.exists(git_repo):
        os.makedirs(git_repo)
    if not os.path.exists(os.path.join(git_repo, '.git')):
        git.init(git_repo)

    data_dir = os.path.abspath(arguments['<data_dir>'])
    root = os.path.join(data_dir, 'pages')
    pages = os.listdir(root)
    os.chdir(git_repo)
    for page in pages:
        versions = get_versions(page, users=users, data_dir=data_dir)
        if not versions:
            print("### ignoring %s (no revisions found)" % page)
            continue
        path = _unquote(page) + '.rst'
        print("### Creating %s\n" % path)
        dirname, basename = os.path.split(path)
        if dirname and not os.path.exists(dirname):
            os.makedirs(dirname)

        for version in versions:
            print("revision %s" % version.pop('revision'))
            with open(path, 'w') as f:
                f.write(version.pop('content'))
            try:
                git.add(path)
                git.commit(path, allow_empty_message=True, **version)
            except:
                pass
Ejemplo n.º 3
0
 def add(self, paths, msg="Intializating"):
     """
         Initializes Directory as repository if not already git repo.
         and adds uncommited changes automatically
     """
     for path in paths:
         global git
         git = git.bake("--git-dir={0}/.git".format(path),
                        "--work-tree={0}".format(path))
         if os.path.isdir(path):
             if not os.path.isdir(path+"/.git"):
                 try:
                     Log.debug(self, "EEGit: git init at {0}"
                               .format(path))
                     git.init(path)
                 except ErrorReturnCode as e:
                     Log.debug(self, "{0}".format(e))
                     Log.error(self, "Unable to git init at {0}"
                               .format(path))
             status = git.status("-s")
             if len(status.splitlines()) > 0:
                 try:
                     Log.debug(self, "EEGit: git commit at {0}"
                               .format(path))
                     git.add("--all")
                     git.commit("-am {0}".format(msg))
                 except ErrorReturnCode as e:
                     Log.debug(self, "{0}".format(e))
                     Log.error(self, "Unable to git commit at {0} "
                               .format(path))
         else:
             Log.debug(self, "EEGit: Path {0} not present".format(path))
Ejemplo n.º 4
0
    def init(self, address, type):
        '''
        Create a new component repository
        '''
        path = self.path(address)
        if os.path.exists(path):
            raise Exception('Component repository already exists at %s' % path)
        git.init(path)
        self.setup(path)

        # Add necessary files and create a first commit. If there are no
        # files added then commit will fail
        if type == 'stencil':
            file(os.path.join(path, 'stencil.cila'), 'w').write('')
            self.git(path, 'add', 'stencil.cila')
        elif type == 'sheet':
            file(os.path.join(path, 'sheet.tsv'), 'w').write('')
            self.git(path, 'add', 'sheet.tsv')
        else:
            raise Exception('No file added for initial commit')
        self.git(path, 'commit', '-m', 'Initial commit')

        # Save the component page as index.html
        com = self.component(address)
        com.page('index.html')
Ejemplo n.º 5
0
 def add(self, paths, msg="Intializating"):
     """
         Initializes Directory as repository if not already git repo.
         and adds uncommited changes automatically
     """
     for path in paths:
         global git
         git = git.bake("--git-dir={0}/.git".format(path),
                        "--work-tree={0}".format(path))
         if os.path.isdir(path):
             if not os.path.isdir(path + "/.git"):
                 try:
                     Log.debug(self, "EEGit: git init at {0}".format(path))
                     git.init(path)
                 except ErrorReturnCode as e:
                     Log.debug(self, "{0}".format(e))
                     Log.error(self,
                               "Unable to git init at {0}".format(path))
             status = git.status("-s")
             if len(status.splitlines()) > 0:
                 try:
                     Log.debug(self,
                               "EEGit: git commit at {0}".format(path))
                     git.add("--all")
                     git.commit("-am {0}".format(msg))
                 except ErrorReturnCode as e:
                     Log.debug(self, "{0}".format(e))
                     Log.error(self,
                               "Unable to git commit at {0} ".format(path))
         else:
             Log.debug(self, "EEGit: Path {0} not present".format(path))
Ejemplo n.º 6
0
 def __init__(self):
     self.__dict__ = self.__shared_state
     from waliki.settings import WALIKI_DATA_DIR
     self.content_dir = WALIKI_DATA_DIR
     os.chdir(self.content_dir)
     if not os.path.isdir(os.path.join(self.content_dir, '.git')):
         git.init()
         self.commit('.', 'initial commit')
Ejemplo n.º 7
0
 def __init__(self):
     self.__dict__ = self.__shared_state
     from waliki.settings import WALIKI_DATA_DIR
     self.content_dir = WALIKI_DATA_DIR
     os.chdir(self.content_dir)
     if not os.path.isdir(os.path.join(self.content_dir, '.git')):
         git.init()
         self.commit('.', 'initial commit')
Ejemplo n.º 8
0
    def init(self, username, reponame, force, backend=None):
        """
        Initialize a Git repo

        Parameters
        ----------

        username, reponame : Repo name is tuple (name, reponame)
        force: force initialization of the repo even if exists
        backend: backend that must be used for this (e.g. s3)
        """
        key = self.key(username, reponame)

        # In local filesystem-based server, add a repo
        server_repodir = self.server_rootdir(username,
                                             reponame,
                                             create=False)

        # Force cleanup if needed
        if os.path.exists(server_repodir) and not force:
            raise RepositoryExists()

        if os.path.exists(server_repodir):
            shutil.rmtree(server_repodir)
        os.makedirs(server_repodir)

        # Initialize the repo
        with cd(server_repodir):
            git.init(".", "--bare")

        if backend is not None:
            backend.init_repo(server_repodir)

        # Now clone the filesystem-based repo
        repodir = self.rootdir(username, reponame, create=False)

        # Prepare it if needed
        if os.path.exists(repodir) and not force:
            raise Exception("Local repo already exists")
        if os.path.exists(repodir):
            shutil.rmtree(repodir)
        os.makedirs(repodir)

        # Now clone...
        with cd(os.path.dirname(repodir)):
            git.clone(server_repodir, '--no-hardlinks')

        url = server_repodir
        if backend is not None:
            url = backend.url(username, reponame)

        repo = Repo(username, reponame)
        repo.manager = self
        repo.remoteurl = url
        repo.rootdir = self.rootdir(username, reponame)

        self.add(repo)
        return repo
Ejemplo n.º 9
0
    def init(self, username, reponame, force, backend=None):
        """
        Initialize a Git repo

        Parameters
        ----------

        username, reponame : Repo name is tuple (name, reponame)
        force: force initialization of the repo even if exists
        backend: backend that must be used for this (e.g. s3)
        """
        key = self.key(username, reponame)

        # In local filesystem-based server, add a repo
        server_repodir = self.server_rootdir(username,
                                             reponame,
                                             create=False)

        # Force cleanup if needed
        if os.path.exists(server_repodir) and not force:
            raise RepositoryExists()

        if os.path.exists(server_repodir):
            shutil.rmtree(server_repodir)
        os.makedirs(server_repodir)

        # Initialize the repo
        with cd(server_repodir):
            git.init(".", "--bare")

        if backend is not None:
            backend.init_repo(server_repodir)

        # Now clone the filesystem-based repo
        repodir = self.rootdir(username, reponame, create=False)

        # Prepare it if needed
        if os.path.exists(repodir) and not force:
            raise Exception("Local repo already exists")
        if os.path.exists(repodir):
            shutil.rmtree(repodir)
        os.makedirs(repodir)

        # Now clone...
        with cd(os.path.dirname(repodir)):
            git.clone(server_repodir, '--no-hardlinks')

        url = server_repodir
        if backend is not None:
            url = backend.url(username, reponame)

        repo = Repo(username, reponame)
        repo.manager = self
        repo.remoteurl = url
        repo.rootdir = self.rootdir(username, reponame)

        self.add(repo)
        return repo
Ejemplo n.º 10
0
 def __init__(self):
     self.__dict__ = self.__shared_state
     from waliki.settings import WALIKI_DATA_DIR
     self.content_dir = WALIKI_DATA_DIR
     os.chdir(self.content_dir)
     if not os.path.isdir(os.path.join(self.content_dir, '.git')):
         git.init()
         git.config("user.email", settings.WALIKI_COMMITTER_EMAIL)
         git.config("user.name", settings.WALIKI_COMMITTER_NAME)
Ejemplo n.º 11
0
    def __init__(self):
        self.__dict__ = self.__shared_state
        self.content_dir = settings.WALIKI_DATA_DIR
        os.chdir(self.content_dir)
        if not os.path.isdir(os.path.join(self.content_dir, '.git')):
            git.init()
            git.config("user.email", settings.WALIKI_COMMITTER_EMAIL)
            git.config("user.name", settings.WALIKI_COMMITTER_NAME)

        self.git = git
Ejemplo n.º 12
0
def cloneWiki(name, cloneUrl):
    sh.cd("../")
    sh.mkdir(name + ".wiki")
    sh.cd(name + ".wiki")
    git.init()
    try:
        git.remote.add(name, cloneUrl[:-4]+ ".wiki.git")
        sh.touch("home.md")
        pushAll("Initial Wiki commit")
    except: print("Wiki remote already exists")
    sh.cd("../" + name)
Ejemplo n.º 13
0
    def init(self):
        """Create a new repository with an initial commit."""

        cwd = os.getcwd()

        git.init(self.__path)

        os.chdir(self.__path)
        git.commit(
            m='Initializing empty Tut project.',
            allow_empty=True,
        )

        os.chdir(cwd)
Ejemplo n.º 14
0
    def install_app(self, appid, pdpobject):
        print "Creating app : %s on heroku" % appid
        r = self._create_app(appid)
        if r.ok:
            print "Successfully created"
        else:
            print "Error creating application"
            print r.status_code, r.text
            return

        resp = r.json()

        git_url = resp["git_url"]
        web_url = resp["web_url"]
        print "Staging PDP archive.."
        print "PDP archive is at : %s" % pdpobject.pdpdir
        print "Configuring git.."
        cwd = os.getcwd()
        os.chdir(pdpobject.pdpdir)
        from sh import git
        git.init()

        print "Invoking the right artifact handler"
        plan = pdpobject.plan
        for a in plan.artifacts:
            h = self.handler_map.get(a.type)
            if h is None:
                raise NotImplementedError("No handler for artifact type : %s" % a.type)
            ho = h(pdpobject, a)
            ho.handle_artifact()

        print "Configuring git remote.."
        git.remote.add("heroku", git_url)


        def process_output(line):
            print(line)

        print "Adding files to repo"
        git.add(".")
        print "Committing to local repo"
        git.commit("-m", "Initial commit")
        print "Pushing to heroku"
        git.push("-u", "heroku", "master", _out=process_output, _tty_out=True)

        print "Uploaded app successfully.."
        print "App is available at : %s" % web_url

        return appid, git_url, web_url
Ejemplo n.º 15
0
    def install_app(self, appid, pdpobject):
        print "Creating app : %s on heroku" % appid
        r = self._create_app(appid)
        if r.ok:
            print "Successfully created"
        else:
            print "Error creating application"
            print r.status_code, r.text
            return

        resp = r.json()

        git_url = resp["git_url"]
        web_url = resp["web_url"]
        print "Staging PDP archive.."
        print "PDP archive is at : %s" % pdpobject.pdpdir
        print "Configuring git.."
        cwd = os.getcwd()
        os.chdir(pdpobject.pdpdir)
        from sh import git
        git.init()

        print "Invoking the right artifact handler"
        plan = pdpobject.plan
        for a in plan.artifacts:
            h = self.handler_map.get(a.type)
            if h is None:
                raise NotImplementedError("No handler for artifact type : %s" %
                                          a.type)
            ho = h(pdpobject, a)
            ho.handle_artifact()

        print "Configuring git remote.."
        git.remote.add("heroku", git_url)

        def process_output(line):
            print(line)

        print "Adding files to repo"
        git.add(".")
        print "Committing to local repo"
        git.commit("-m", "Initial commit")
        print "Pushing to heroku"
        git.push("-u", "heroku", "master", _out=process_output, _tty_out=True)

        print "Uploaded app successfully.."
        print "App is available at : %s" % web_url

        return appid, git_url, web_url
Ejemplo n.º 16
0
def initializeDir(path, user, repo = None):
    if not os.path.exists(path):
        print('making directories')
        os.makedirs(path)
    os.chdir(path)
    if os.path.exists('.git/'):
        print('git respository already initialized')
        return
    print('initializing git repository')
    git.init()
    os.chmod(path + '/.git/', 0b111000000)
    git.config('--local', 'user.name', '"' + user['name'] + '"')
    git.config('--local', 'user.email', '"' + user['email'] + '"')
    if repo:
        git.remote.add('origin', repo)
Ejemplo n.º 17
0
def test_git_repo():
    # create repo
    repo_dir = tempdir.TempDir()
    gitsh.init(repo_dir.name)
    # put something in the description file:
    description = open('{}/.git/description'.format(repo_dir.name), 'w')
    overwrite(description, 'Depeche Mode')
    # create a single file
    repo_file = tempfile.NamedTemporaryFile(dir=repo_dir.name, delete=False)
    overwrite(repo_file, '123\n')
    # commit it
    gitsh.add(repo_file.name, _cwd=repo_dir.name)
    gitsh.commit(m='message', author='First Last <*****@*****.**>',
                 _cwd=repo_dir.name)
    return repo_dir
Ejemplo n.º 18
0
def initializeDir(path, user, repo=None):
    if not os.path.exists(path):
        print('making directories')
        os.makedirs(path)
    os.chdir(path)
    if os.path.exists('.git/'):
        print('git respository already initialized')
        return
    print('initializing git repository')
    git.init()
    os.chmod(path + '/.git/', 0b111000000)
    git.config('--local', 'user.name', '"' + user['name'] + '"')
    git.config('--local', 'user.email', '"' + user['email'] + '"')
    if repo:
        git.remote.add('origin', repo)
Ejemplo n.º 19
0
Archivo: git.py Proyecto: kball/ambry
 def init(self):
     o = git.init()
     
     if o.exit_code != 0:
         raise RepositoryException("Failed to init git repo: {}".format(o))
     
     return True
Ejemplo n.º 20
0
def get_repo(repodir):
    repo = None
    try:
        if not os.path.exists(repodir):
            os.makedirs(repodir)
        repo = git.init(repodir)
    except Exception as e:
        logger.error(str(e))
        
    return repo
Ejemplo n.º 21
0
    def test_update_docs(self, tmpdir, caplog):
        k = {"_cwd": str(tmpdir)}
        git.init(**k)
        git.config("user.email", "*****@*****.**", **k)
        git.config("user.name", "Your Name", **k)
        os.makedirs(join(str(tmpdir), "docs/includes"))
        touch("docs/includes/l10n.txt", **k)
        git.add("docs/includes/l10n.txt", **k)
        git.commit("-m", "init", **k)

        i18n_tool.I18NTool().main(
            ["--verbose", "update-docs", "--docs-repo-dir",
             str(tmpdir)])
        assert "l10n.txt updated" in caplog.text
        caplog.clear()
        i18n_tool.I18NTool().main(
            ["--verbose", "update-docs", "--docs-repo-dir",
             str(tmpdir)])
        assert "l10n.txt already up to date" in caplog.text
Ejemplo n.º 22
0
    def test_update_docs(self, tmpdir, caplog):
        k = {'_cwd': str(tmpdir)}
        git.init(**k)
        git.config('user.email', "*****@*****.**", **k)
        git.config('user.name', "Your Name", **k)
        os.mkdir(join(str(tmpdir), 'includes'))
        touch('includes/l10n.txt', **k)
        git.add('includes/l10n.txt', **k)
        git.commit('-m', 'init', **k)

        i18n_tool.I18NTool().main(
            ['--verbose', 'update-docs', '--documentation-dir',
             str(tmpdir)])
        assert 'l10n.txt updated' in caplog.text
        caplog.clear()
        i18n_tool.I18NTool().main(
            ['--verbose', 'update-docs', '--documentation-dir',
             str(tmpdir)])
        assert 'l10n.txt already up to date' in caplog.text
Ejemplo n.º 23
0
def get_repo(repodir):
    repo = None
    try:
        if not os.path.exists(repodir):
            os.makedirs(repodir)
        repo = git.init(repodir)
    except Exception as e:
        logger.error(str(e))

    return repo
Ejemplo n.º 24
0
    def init(self):
        """Create a new repository with an initial commit."""

        cwd = os.getcwd()

        # initialize the empty repository
        git.init(self.path)

        self._git('commit',
            m='Initializing empty Tut project.',
            allow_empty=True,
        )

        # create the empty configuration file
        self._git('branch', 'tut')
        self._update_config(
            DEFAULT_CONFIG,
            log='Initializing Tut configuration.',
        )
        self._git('checkout', 'master')
Ejemplo n.º 25
0
    def __init__(self,
                 path,
                 repo_name,
                 clone_url=None,
                 branch="master",
                 bare=False):
        """Creates a new repository in the directory @path/@repo_name.
           If @clone_url is not None, it creates it by cloning it
           from @clone_url. Otherwise it initializes a new repo.
           The repository will be bare if @bare is True."""

        self._workdir = os.path.join(path, repo_name)

        if not os.path.isdir(self._workdir):
            self._remote = clone_url
            if self._remote:
                if branch is not None:
                    git.clone("--branch",
                              branch,
                              self._remote,
                              self._workdir,
                              bare=bare)
                else:
                    git.clone(self._remote, self._workdir, bare=bare)
            else:
                git.init(self._workdir, bare=bare)
        else:
            if os.path.isfile(os.path.join(self._workdir, '.git/config')):
                cfg = os.path.join(self._workdir, '.git/config')
            else:
                cfg = os.path.join(self._workdir, 'config')
            config = open(cfg).read()
            m = re.match('^.*\s*url\s*=\s*(?P<url>[^\s]*)\s.*$', config,
                         re.IGNORECASE | re.DOTALL)
            if m:
                self._remote = m.groupdict()['url']
            else:
                self._remote = None
        self._git = git.bake(_cwd=self._workdir, _tty_out=False)
Ejemplo n.º 26
0
    def test_clone_git_repo(self, mock_working_dir):

        # Create a fake temp repo w/ commit
        git_dir = tempfile.mkdtemp(prefix='git')
        git.init(git_dir)

        try:
            f = open(os.path.join(git_dir, 'foo.txt'), 'w')
            f.write('blah')
        except IOError:
            assert False
        finally:
            f.close()
        cwd = os.getcwd()
        os.chdir(git_dir)
        git.add('foo.txt')
        if os.environ.get('TRAVIS_CI') == 'true':
            git.config('--global', 'user.email',
                       '"*****@*****.**"')
            git.config('--global', 'user.name',
                       '"Testing on Travis CI"')
        git.commit('-m "Added foo.txt"')
        os.chdir(cwd)

        # Fake Template Path
        mock_working_dir.return_value = tempfile.gettempdir()

        # Now attempt to clone but patch for Exception throw
        self.config.template = 'git+' + git_dir
        self.config._tpl = git_dir
        t = Template(self.config)
        t.copy_template()

        # Clean up
        rmtree(t.project_root)

        self.assertFalse(os.path.isdir(t.config.template))
        self.assertFalse(self.config.cli_opts.error.called)
Ejemplo n.º 27
0
    def init(self):
        """Create a new repository with an initial commit."""

        cwd = os.getcwd()

        # initialize the empty repository
        git.init(self.path)
        os.chdir(self.path)

        git.commit(
            m='Initializing empty Tut project.',
            allow_empty=True,
        )

        # create the empty configuration file
        git.branch('tut')
        self._update_config(
            DEFAULT_CONFIG,
            log='Initializing Tut configuration.',
        )
        git.checkout('master')

        os.chdir(cwd)
Ejemplo n.º 28
0
    def test_clone_git_repo(self, mock_working_dir):

        # Create a fake temp repo w/ commit
        git_dir = tempfile.mkdtemp(prefix='git')
        git.init(git_dir)

        try:
            f = open(os.path.join(git_dir, 'foo.txt'), 'w')
            f.write('blah')
        except IOError:
            assert False
        finally:
            f.close()
        cwd = os.getcwd()
        os.chdir(git_dir)
        git.add('foo.txt')
        if os.environ.get('TRAVIS_CI') == 'true':
            git.config('--global', 'user.email',
                       '"*****@*****.**"')
            git.config('--global', 'user.name', '"Testing on Travis CI"')
        git.commit('-m "Added foo.txt"')
        os.chdir(cwd)

        # Fake Template Path
        mock_working_dir.return_value = tempfile.gettempdir()

        # Now attempt to clone but patch for Exception throw
        self.config.template = 'git+' + git_dir
        self.config._tpl = git_dir
        t = Template(self.config)
        t.copy_template()

        # Clean up
        rmtree(t.project_root)

        self.assertFalse(os.path.isdir(t.config.template))
        self.assertFalse(self.config.cli_opts.error.called)
Ejemplo n.º 29
0
def migrate_to_git():
    if arguments['--users-file']:
        users = json.loads(open(arguments['<users_file>']).read())
    else:
        users = parse_users()
    git_repo = arguments['<git_repo>']

    if not os.path.exists(git_repo):
        os.makedirs(git_repo)
    if not os.path.exists(os.path.join(git_repo, '.git')):
        git.init(git_repo)

    data_dir = os.path.abspath(arguments['<data_dir>'])
    root = os.path.join(data_dir, 'pages')
    pages = os.listdir(root)
    os.chdir(git_repo)
    for page in pages:
        versions = get_versions(page, users=users, data_dir=data_dir)
        if not versions:
            print("### ignoring %s (no revisions found)" % page)
            continue
        path = _unquote(page) + '.rst'
        print("### Creating %s\n" % path)
        dirname, basename = os.path.split(path)
        if dirname and not os.path.exists(dirname):
            os.makedirs(dirname)

        for version in versions:
            print("revision %s" % version.pop('revision'))
            with open(path, 'w') as f:
                f.write(version.pop('content'))
            try:
                git.add(path)
                git.commit(path, allow_empty_message=True, **version)
            except:
                pass
Ejemplo n.º 30
0
def check_git_repo(git_path):
    """
    make sure there's actually a git repo initialized and
    check the git-diff exit code for changes if it exists

    git-diff exit codes:
    - 0: no changes
    - 1: changes
    - 129: no git repo
    """
    os.chdir(git_path)
    changed = False
    created = False
    try:
        git("diff", "--exit-code")
    except sh.ErrorReturnCode_1:
        changed = True
    except sh.ErrorReturnCode_129:
        click.echo("no git repo found; initializing a new repo")
        git.init()
        git.add(".")
        click.echo(git.commit('-m"Initial commit"'))
        created = True
    return created, changed
Ejemplo n.º 31
0
def check_git_repo(git_path):
    """
    make sure there's actually a git repo initialized and
    check the git-diff exit code for changes if it exists

    git-diff exit codes:
    - 0: no changes
    - 1: changes
    - 129: no git repo
    """
    os.chdir(git_path)
    changed = False
    created = False
    try:
        git("diff", "--exit-code")
    except sh.ErrorReturnCode_1:
        changed = True
    except sh.ErrorReturnCode_129:
        click.echo("no git repo found; initializing a new repo")
        git.init()
        git.add(".")
        click.echo(git.commit('-m"Initial commit"'))
        created = True
    return created, changed
Ejemplo n.º 32
0
 def setUp(self):
     super(TestCore, self).setUp('gl-core-test')
     git.init()
     utils_lib.set_test_config()
     self.repo = core.Repository()
Ejemplo n.º 33
0
def migrate_to_git():
    if arguments['--users-file']:
        users = json.loads(open(arguments['<users_file>']).read())
    else:
        users = parse_users()
    git_repo = arguments['<git_repo>']

    if not os.path.exists(git_repo):
        os.makedirs(git_repo)
    if not os.path.exists(os.path.join(git_repo, '.git')):
        git.init(git_repo)

    data_dir = os.path.abspath(arguments['<data_dir>'])
    root = os.path.join(data_dir, 'pages')
    pages = os.listdir(root)
    os.chdir(git_repo)
    for page in pages:
        if page in CONVERSION_BLACKLIST:
            continue
        versions = get_versions(page, users=users, data_dir=data_dir)
        if not versions:
            print("### ignoring %s (no revisions found)" % page)
            continue
        path = _hyphenize(_unquote(page)) + '.txt'
        print("### Creating %s\n" % path)
        dirname, basename = os.path.split(path)
        if dirname and not os.path.exists(dirname):
            os.makedirs(dirname)

        for version in versions:
            revision = version.pop('revision')
            # Handle attachment revisions
            if revision == '99999999':
                continue
            print("revision %s" % revision)
            try:
                if version['content']:
                    with open(path, 'w') as f:
                        print("Opening %s" % path)
                        f.write(version.pop('content'))
                    print("Adding %s" % path)
                    git.add(path)
                else:
                    print("Removing %s" % path)
                    git.rm(path)
                    version.pop('content')
                if version['rst_content']:
                    with open(path.replace('txt', 'rst'), 'w') as f:
                        print("Opening %s" % path.replace('txt', 'rst'))
                        f.write(version.pop('rst_content'))
                    pandoc(path.replace('txt', 'rst'),
                           f="rst",
                           t="markdown_github",
                           o=path.replace('txt', 'md'))
                    print("Adding %s" % path.replace('txt', 'rst'))
                    git.add(path.replace('txt', 'rst'))
                    print("Adding %s" % path.replace('txt', 'md'))
                    git.add(path.replace('txt', 'md'))
                elif os.path.isfile(path.replace('txt', 'rst')):
                    print("Removing %s" % path.replace('txt', 'rst'))
                    git.rm(path.replace('txt', 'rst'))
                    print("Removing %s" % path.replace('txt', 'md'))
                    git.rm(path.replace('txt', 'md'))
                    version.pop('rst_content')
                else:
                    version.pop('rst_content')
                print("Committing %s" % path)
                print(version['m'])
                if not version['m'].strip():
                    version['m'] = "Change made on %s" % version[
                        'date'].strftime('%x')
                git.commit(path.replace('txt', '*'), **version)
            except Exception as e:
                print(e)
Ejemplo n.º 34
0
def init(template=False):
    """ Creates a new repository, copying the default template if one is provided."""
    if ( template ) :
        git.init("--template", template)
    else :
        git.init()
Ejemplo n.º 35
0
    def test_update_from_weblate(self, tmpdir, caplog):
        d = str(tmpdir)
        for repo in ("i18n", "securedrop"):
            os.mkdir(join(d, repo))
            k = {"_cwd": join(d, repo)}
            git.init(**k)
            git.config("user.email", "*****@*****.**", **k)
            git.config("user.name", "Loïc Nordhøy", **k)
            touch("README.md", **k)
            git.add("README.md", **k)
            git.commit("-m", "README", "README.md", **k)
        for o in os.listdir(join(self.dir, "i18n")):
            f = join(self.dir, "i18n", o)
            if os.path.isfile(f):
                shutil.copyfile(f, join(d, "i18n", o))
            else:
                shutil.copytree(f, join(d, "i18n", o))
        k = {"_cwd": join(d, "i18n")}
        git.add("securedrop", "install_files", **k)
        git.commit("-m", "init", "-a", **k)
        git.checkout("-b", "i18n", "master", **k)

        def r():
            return "".join([str(l) for l in caplog.records])

        #
        # de_DE is not amount the supported languages, it is not taken
        # into account despite the fact that it exists in weblate.
        #
        caplog.clear()
        i18n_tool.I18NTool().main([
            "--verbose",
            "update-from-weblate",
            "--root",
            join(str(tmpdir), "securedrop"),
            "--url",
            join(str(tmpdir), "i18n"),
            "--supported-languages",
            "nl",
        ])
        assert "l10n: updated Dutch (nl)" in r()
        assert "l10n: updated German (de_DE)" not in r()

        #
        # de_DE is added but there is no change in the nl translation
        # therefore nothing is done for nl
        #
        caplog.clear()
        i18n_tool.I18NTool().main([
            "--verbose",
            "update-from-weblate",
            "--root",
            join(str(tmpdir), "securedrop"),
            "--url",
            join(str(tmpdir), "i18n"),
            "--supported-languages",
            "nl,de_DE",
        ])
        assert "l10n: updated Dutch (nl)" not in r()
        assert "l10n: updated German (de_DE)" in r()

        #
        # nothing new for nl or de_DE: nothing is done
        #
        caplog.clear()
        i18n_tool.I18NTool().main([
            "--verbose",
            "update-from-weblate",
            "--root",
            join(str(tmpdir), "securedrop"),
            "--url",
            join(str(tmpdir), "i18n"),
            "--supported-languages",
            "nl,de_DE",
        ])
        assert "l10n: updated Dutch (nl)" not in r()
        assert "l10n: updated German (de_DE)" not in r()
        message = str(
            git("--no-pager",
                "-C",
                "securedrop",
                "show",
                _cwd=d,
                _encoding="utf-8"))
        assert "Loïc" in message

        #
        # an update is done to nl in weblate
        #
        k = {"_cwd": join(d, "i18n")}
        f = "securedrop/translations/nl/LC_MESSAGES/messages.po"
        sed("-i", "-e", "s/inactiviteit/INACTIVITEIT/", f, **k)
        git.add(f, **k)
        git.config("user.email", "*****@*****.**", **k)
        git.config("user.name", "Someone Else", **k)
        git.commit("-m", "translation change", f, **k)

        k = {"_cwd": join(d, "securedrop")}
        git.config("user.email", "*****@*****.**", **k)
        git.config("user.name", "Someone Else", **k)

        #
        # the nl translation update from weblate is copied
        # over.
        #
        caplog.clear()
        i18n_tool.I18NTool().main([
            "--verbose",
            "update-from-weblate",
            "--root",
            join(str(tmpdir), "securedrop"),
            "--url",
            join(str(tmpdir), "i18n"),
            "--supported-languages",
            "nl,de_DE",
        ])
        assert "l10n: updated Dutch (nl)" in r()
        assert "l10n: updated German (de_DE)" not in r()
        message = str(git("--no-pager", "-C", "securedrop", "show", _cwd=d))
        assert "Someone Else" in message
        assert "Loïc" not in message
Ejemplo n.º 36
0
def init_project_directory_with_git():
    # initialize the new project directory with git
    git.init()
Ejemplo n.º 37
0
 def setUp(self):
   super(TestCore, self).setUp('gl-core-test')
   git.init()
   utils_lib.set_test_config()
   self.repo = core.Repository()
Ejemplo n.º 38
0
    def _get_provisioner_repo(self):
        # Use the configured git repository, if any
        provisioner_git_repo = self.config.get('git_repo')
        provisioner_git_revision = self.config.get('git_revision')

        git_local_mirror = self._get_mirror_path(provisioner_git_repo)
        zabbix_repo = self.global_config.get('zabbix_repo', ZABBIX_REPO)
        lock_path = get_lock_path_from_repo(provisioner_git_repo)
        log(
            "Getting provisioner features from {r}".format(
                r=provisioner_git_repo), self._log_file)
        try:
            output = git("ls-remote", "--exit-code", provisioner_git_repo,
                         provisioner_git_revision).strip()
            log(
                "Provisioner repository checked successfuly with output: " +
                output, self._log_file)
        except sh.ErrorReturnCode:
            log(
                "Invalid provisioner repository or invalid credentials. Please check your yaml 'config.yml' file",
                self._log_file)
            raise

        try:
            git_acquire_lock(lock_path, self._log_file)

            # Creates the Provisioner local mirror
            if not os.path.exists(git_local_mirror):
                log(
                    "Creating local mirror [{r}] for the first time".format(
                        r=git_local_mirror), self._log_file)
                os.makedirs(git_local_mirror)
                os.chdir(git_local_mirror)
                git.init(['--bare'])
                git.remote(['add', self.name, provisioner_git_repo])
                git.remote(['add', 'zabbix', zabbix_repo])

            log(
                "Fetching local mirror [{r}] remotes".format(
                    r=git_local_mirror), self._log_file)
            os.chdir(git_local_mirror)
            git.fetch(['--all'])
        finally:
            git_release_lock(lock_path, self._log_file)

        log(
            "Cloning [{r}] repo with local mirror reference".format(
                r=provisioner_git_repo), self._log_file)
        git.clone([
            '--reference', git_local_mirror, provisioner_git_repo, '-b',
            provisioner_git_revision, '--single-branch',
            self.local_repo_path + '/'
        ])
        if os.path.exists(self.local_repo_path + '/.gitmodules'):
            os.chdir(self.local_repo_path)
            log("Re-map submodules on local git mirror", self._log_file)
            git_remap_submodule(self.local_repo_path, zabbix_repo,
                                git_local_mirror, self._log_file)
            log("Submodule init and update", self._log_file)
            git.submodule('init')
            git.submodule('update')
Ejemplo n.º 39
0
    def test_update_from_weblate(self, tmpdir, caplog):
        d = str(tmpdir)
        for repo in ('i18n', 'securedrop'):
            os.mkdir(join(d, repo))
            k = {'_cwd': join(d, repo)}
            git.init(**k)
            git.config('user.email', '*****@*****.**', **k)
            git.config('user.name',  'Loïc Nordhøy', **k)
            touch('README.md', **k)
            git.add('README.md', **k)
            git.commit('-m', 'README', 'README.md', **k)
        for o in os.listdir(join(self.dir, 'i18n')):
            f = join(self.dir, 'i18n', o)
            if os.path.isfile(f):
                shutil.copyfile(f, join(d, 'i18n', o))
            else:
                shutil.copytree(f, join(d, 'i18n', o))
        k = {'_cwd': join(d, 'i18n')}
        git.add('securedrop', 'install_files', **k)
        git.commit('-m', 'init', '-a', **k)
        git.checkout('-b', 'i18n', 'master', **k)

        def r():
            return "".join([str(l) for l in caplog.records])

        #
        # de_DE is not amount the supported languages, it is not taken
        # into account despite the fact that it exists in weblate.
        #
        caplog.clear()
        i18n_tool.I18NTool().main([
            '--verbose',
            'update-from-weblate',
            '--root', join(str(tmpdir), 'securedrop'),
            '--url', join(str(tmpdir), 'i18n'),
            '--supported-languages', 'nl',
        ])
        assert 'l10n: updated Dutch (nl)' in r()
        assert 'l10n: updated German (de_DE)' not in r()

        #
        # de_DE is added but there is no change in the nl translation
        # therefore nothing is done for nl
        #
        caplog.clear()
        i18n_tool.I18NTool().main([
            '--verbose',
            'update-from-weblate',
            '--root', join(str(tmpdir), 'securedrop'),
            '--url', join(str(tmpdir), 'i18n'),
            '--supported-languages', 'nl,de_DE',
        ])
        assert 'l10n: updated Dutch (nl)' not in r()
        assert 'l10n: updated German (de_DE)' in r()

        #
        # nothing new for nl or de_DE: nothing is done
        #
        caplog.clear()
        i18n_tool.I18NTool().main([
            '--verbose',
            'update-from-weblate',
            '--root', join(str(tmpdir), 'securedrop'),
            '--url', join(str(tmpdir), 'i18n'),
            '--supported-languages', 'nl,de_DE',
        ])
        assert 'l10n: updated Dutch (nl)' not in r()
        assert 'l10n: updated German (de_DE)' not in r()
        message = str(git('--no-pager', '-C', 'securedrop', 'show',
                          _cwd=d, _encoding='utf-8'))
        assert "Loïc" in message

        #
        # an update is done to nl in weblate
        #
        k = {'_cwd': join(d, 'i18n')}
        f = 'securedrop/translations/nl/LC_MESSAGES/messages.po'
        sed('-i', '-e', 's/inactiviteit/INACTIVITEIT/', f, **k)
        git.add(f, **k)
        git.config('user.email', '*****@*****.**', **k)
        git.config('user.name', 'Someone Else', **k)
        git.commit('-m', 'translation change', f, **k)

        k = {'_cwd': join(d, 'securedrop')}
        git.config('user.email', '*****@*****.**', **k)
        git.config('user.name', 'Someone Else', **k)

        #
        # the nl translation update from weblate is copied
        # over.
        #
        caplog.clear()
        i18n_tool.I18NTool().main([
            '--verbose',
            'update-from-weblate',
            '--root', join(str(tmpdir), 'securedrop'),
            '--url', join(str(tmpdir), 'i18n'),
            '--supported-languages', 'nl,de_DE',
        ])
        assert 'l10n: updated Dutch (nl)' in r()
        assert 'l10n: updated German (de_DE)' not in r()
        message = str(git('--no-pager', '-C', 'securedrop', 'show',
                          _cwd=d))
        assert "Someone Else" in message
        assert "Loïc" not in message