Example #1
0
    def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
        """Initialize a git repository at the given path if specified

        :param path:
            is the full path to the repo (traditionally ends with /<name>.git)
            or None in which case the repository will be created in the current
            working directory

        :parm mkdir:
            if specified will create the repository directory if it doesn't
            already exists. Creates the directory with a mode=0755.
            Only effective if a path is explicitly given

        :param odbt:
            Object DataBase type - a type which is constructed by providing
            the directory containing the database objects, i.e. .git/objects.
            It will be used to access all object data

        :parm kwargs:
            keyword arguments serving as additional options to the git-init command

        :return: ``git.Repo`` (the newly created repo)"""
        if path:
            path = _expand_path(path)
        if mkdir and path and not os.path.exists(path):
            os.makedirs(path, 0o755)

        # git command automatically chdir into the directory
        git = Git(path)
        git.init(**kwargs)
        return cls(path, odbt=odbt)
Example #2
0
    def init(cls, path=None, mkdir=True, **kwargs):
        """Initialize a git repository at the given path if specified

        :param path:
            is the full path to the repo (traditionally ends with /<name>.git)
            or None in which case the repository will be created in the current
            working directory

        :parm mkdir:
            if specified will create the repository directory if it doesn't
            already exists. Creates the directory with a mode=0755.
            Only effective if a path is explicitly given

        :parm kwargs:
            keyword arguments serving as additional options to the git-init command

        :return: ``git.Repo`` (the newly created repo)"""
        if path:
            path = _expand_path(path)
        if mkdir and path and not os.path.exists(path):
            os.makedirs(path, 0o755)

        # git command automatically chdir into the directory
        git = Git(path)
        git.init(**kwargs)
        return cls(path)
Example #3
0
    def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
        """Initialize a git repository at the given path if specified

        :param path:
            is the full path to the repo (traditionally ends with /<name>.git)
            or None in which case the repository will be created in the current
            working directory

        :parm mkdir:
            if specified will create the repository directory if it doesn't
            already exists. Creates the directory with a mode=0755.
            Only effective if a path is explicitly given

        :param odbt:
            Object DataBase type - a type which is constructed by providing
            the directory containing the database objects, i.e. .git/objects.
            It will be used to access all object data

        :parm kwargs:
            keyword arguments serving as additional options to the git-init command

        :return: ``git.Repo`` (the newly created repo)"""
        if path:
            path = _expand_path(path)
        if mkdir and path and not os.path.exists(path):
            os.makedirs(path, 0o755)

        # git command automatically chdir into the directory
        git = Git(path)
        git.init(**kwargs)
        return cls(path, odbt=odbt)
Example #4
0
    def init(cls, path=None, mkdir=True, **kwargs):
        """Initialize a git repository at the given path if specified

        :param path:
            is the full path to the repo (traditionally ends with /<name>.git)
            or None in which case the repository will be created in the current
            working directory

        :parm mkdir:
            if specified will create the repository directory if it doesn't
            already exists. Creates the directory with a mode=0755.
            Only effective if a path is explicitly given

        :parm kwargs:
            keyword arguments serving as additional options to the git-init command

        :return: ``git.Repo`` (the newly created repo)"""
        if path:
            path = _expand_path(path)
        if mkdir and path and not os.path.exists(path):
            os.makedirs(path, 0o755)

        # git command automatically chdir into the directory
        git = Git(path)
        git.init(**kwargs)
        return cls(path)
Example #5
0
def get():
    parser = reqparse.RequestParser()
    parser.add_argument('repo', location='args', required=True)
    parser.add_argument('port', location='args', required=True)
    data = parser.parse_args()
    repo = data['repo']
    port = data['port']
    try:
        response = requests.get(repo)
        if response.status_code != 200:
            return jsonify({
                'status': 401,
                'error': '{} is not a valid URL'.format(repo)
            })
    except:
        return jsonify({
            'status': 401,
            'error': '{} is not a valid URL'.format(repo)
        })
    gitcmd = Git('.')
    gitcmd.init()
    name = repo.split('/')
    repo_name = name[-1]
    repo_name = repo_name.replace('.git', '')
    gitcmd.clone(repo, 'repos/' + repo_name)
    subprocess.Popen(
        '.flaskapp/bin/uwsgi --http :%s --file repos/{}/wsgi.py --callable app'
        .format(port, repo_name))
    return jsonify({
        'status':
        200,
        'message':
        'Deployed to Raspberry Pi! {} is now running!'.format(repo_name)
    })
Example #6
0
    def __init__(self, *args, **kwargs):
        if not kwargs.get('parent', None):
            # Initialize a new repo
            git_path = mkdtemp(prefix=settings.GIT_ROOT_PATH)
            git = Git(git_path)
            git.init()

            body_path = os.path.join(git_path, 'BODY')

            self.message = "created new"

            kwargs['git_path'] = git_path

        super(Fork, self).__init__(*args, **kwargs)
    def init(cls, path: PathLike = None, mkdir: bool = True, odbt: Type[GitCmdObjectDB] = GitCmdObjectDB,
             expand_vars: bool = True, **kwargs: Any) -> 'Repo':
        """Initialize a git repository at the given path if specified

        :param path:
            is the full path to the repo (traditionally ends with /<name>.git)
            or None in which case the repository will be created in the current
            working directory

        :param mkdir:
            if specified will create the repository directory if it doesn't
            already exists. Creates the directory with a mode=0755.
            Only effective if a path is explicitly given

        :param odbt:
            Object DataBase type - a type which is constructed by providing
            the directory containing the database objects, i.e. .git/objects.
            It will be used to access all object data

        :param expand_vars:
            if specified, environment variables will not be escaped. This
            can lead to information disclosure, allowing attackers to
            access the contents of environment variables

        :param kwargs:
            keyword arguments serving as additional options to the git-init command

        :return: ``git.Repo`` (the newly created repo)"""
        if path:
            path = expand_path(path, expand_vars)
        if mkdir and path and not osp.exists(path):
            os.makedirs(path, 0o755)

        # git command automatically chdir into the directory
        git = Git(path)
        git.init(**kwargs)
        return cls(path, odbt=odbt)
Example #8
0
def init(error, info, debug):
    path = getcwd()
    git = Git(path)

    debug('running git init...')
    debug(git.init())

    welcome_package()
    init_releaserc()

    call_task('commit', options={
        'm': 'Intializing repository'
    })

    init_branches()

    debug('')

    info('Git repository created successfully.')
Example #9
0
    def website_gitrepo(self):
        '''Create a new GitHub repository and populate it with content from
        a newly generated jekyll website export created via :meth:`website`.
        :return: on success, returns a tuple of public repository url and
            github pages url for the newly created repo and site
        '''

        # NOTE: github pages sites now default to https
        github_pages_url = 'https://%s.github.io/%s/' % \
            (self.github_username, self.github_repo)

        # before even starting to generate the jekyll site,
        # check if requested repo name already exists; if so, bail out with an error
        logger.debug('Checking github repo %s for %s', self.github_repo,
                     self.github_username)

        if self.gitrepo_exists():
            raise GithubExportException('GitHub repo %s already exists.' \
                                        % self.github_repo)

        export_dir = self.generate_website()

        # jekyll dir is *inside* the export directory;
        # for the jekyll site to display correctly, we need to commit what
        # is in the directory, not the directory itself
        jekyll_dir = self.edition_dir(export_dir)

        # modify the jekyll config for relative url on github.io
        config_file_path = os.path.join(jekyll_dir, '_config.yml')
        with open(config_file_path, 'r') as configfile:
            config_data = yaml.load(configfile)

        # split out github pages url into the site url and path
        parsed_gh_url = urlparse(github_pages_url)
        config_data['url'] = '%s://%s' % (parsed_gh_url.scheme,
                                          parsed_gh_url.netloc)
        config_data['baseurl'] = parsed_gh_url.path.rstrip('/')
        with open(config_file_path, 'w') as configfile:
            yaml.safe_dump(config_data, configfile, default_flow_style=False)
            # using safe_dump to generate only standard yaml output
            # NOTE: pyyaml requires default_flow_style=false to output
            # nested collections in block format

        logger.debug('Creating github repo %s for %s', self.github_repo,
                     self.github_username)
        if self.update_callback is not None:
            self.update_callback('Creating GitHub repo %s' % self.github_repo)
        self.github.create_repo(
            self.github_repo,
            homepage=github_pages_url,
            description='An annotated digital edition created with Readux')

        # get auth repo url to use to push data
        repo_url = self.github_auth_repo(repo_name=self.github_repo)

        # add the jekyll site to github; based on these instructions:
        # https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

        # initialize export dir as a git repo, and commit the contents
        # NOTE: to debug git commands, print the git return to see git output

        gitcmd = Git(jekyll_dir)
        # initialize jekyll site as a git repo
        gitcmd.init()
        # add and commit all contents
        gitcmd.add(['.'])
        gitcmd.commit([
            '-m',
            'Import Jekyll site generated by Readux %s' % __version__,
            '--author="%s <%s>"' % (self.user.fullname(), self.user.email)
        ])
        # push local master to the gh-pages branch of the newly created repo,
        # using the user's oauth token credentials
        self.log_status('Pushing content to GitHub')
        gitcmd.push([repo_url, 'master:gh-pages'])

        # clean up temporary files after push to github
        shutil.rmtree(export_dir)

        # generate public repo url for display to user
        public_repo_url = 'https://github.com/%s/%s' % (self.github_username,
                                                        self.github_repo)
        return (public_repo_url, github_pages_url)
Example #10
0
    def website_gitrepo(self, user, repo_name):
        '''Create a new GitHub repository and populate it with content from
        a newly generated jekyll website export created via :meth:`website`.

        :param user: user
        :param repo_name: name of the GitHub repository to be created;
            raises :class:`GithubExportException` if the repository already
            exists
        :param vol: :class:`~readux.books.models.Volume` to be exported
            (1.0 or 1.1)
        :param tei: annotated TEI facsimile (e.g.,
            :class:`~readux.books.tei.AnnotatedFacsimile`)
        :param page_one: page where numbering should start from 1 in the export
        :return: on success, returns a tuple of public repository url and
            github pages url for the newly created repo and site
        '''

        # connect to github as the user in order to create the repository
        self.use_github(user)
        # NOTE: github pages sites now default to https
        github_pages_url = 'https://%s.github.io/%s/' % \
            (self.github_username, repo_name)

        # before even starting to generate the jekyll site,
        # check if requested repo name already exists; if so, bail out with an error
        current_repos = self.github.list_repos(self.github_username)
        current_repo_names = [repo['name'] for repo in current_repos]
        if repo_name in current_repo_names:
            raise GithubExportException('GitHub repo %s already exists.' \
                                        % repo_name)

        export_dir = self.generate_website()

        # jekyll dir is *inside* the export directory;
        # for the jekyll site to display correctly, we need to commit what
        # is in the directory, not the directory itself
        jekyll_dir = self.get_jekyll_site_dir(export_dir)

        # modify the jekyll config for relative url on github.io
        config_file_path = os.path.join(jekyll_dir, '_config.yml')
        with open(config_file_path, 'r') as configfile:
            config_data = yaml.load(configfile)

        # split out github pages url into the site url and path
        parsed_gh_url = urlparse(github_pages_url)
        config_data['url'] = '%s://%s' % (parsed_gh_url.scheme,
                                          parsed_gh_url.netloc)
        config_data['baseurl'] = parsed_gh_url.path.rstrip('/')
        with open(config_file_path, 'w') as configfile:
            yaml.safe_dump(config_data, configfile,
                           default_flow_style=False)
            # using safe_dump to generate only standard yaml output
            # NOTE: pyyaml requires default_flow_style=false to output
            # nested collections in block format

        logger.debug('Creating github repo %s for %s', repo_name,
                     self.github_username)
        if self.update_callback is not None:
            self.update_callback('Creating GitHub repo %s' % repo_name)
        self.github.create_repo(
            repo_name, homepage=github_pages_url,
            description='An annotated digital edition created with Readux')

        # get auth repo url to use to push data
        repo_url = self.github_auth_repo(repo_name=repo_name)

        # add the jekyll site to github; based on these instructions:
        # https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

        # initialize export dir as a git repo, and commit the contents
        # NOTE: to debug git commands, print the git return to see git output
        gitcmd = Git(jekyll_dir)
        # initialize jekyll site as a git repo
        gitcmd.init()
        # add and commit all contents
        gitcmd.add(['.'])
        gitcmd.commit(
            ['-m', 'Import Jekyll site generated by Readux %s' % __version__,
             '--author="%s <%s>"' % (settings.GIT_AUTHOR_NAME,
                                     settings.GIT_AUTHOR_EMAIL)])
        # push local master to the gh-pages branch of the newly created repo,
        # using the user's oauth token credentials
        self.log_status('Pushing content to GitHub')
        gitcmd.push([repo_url, 'master:gh-pages'])

        # clean up temporary files after push to github
        shutil.rmtree(export_dir)

        # generate public repo url for display to user
        public_repo_url = 'https://github.com/%s/%s' % (self.github_username,
                                                        repo_name)
        return (public_repo_url, github_pages_url)