Example #1
0
def django(ctx, req, packages, frontend, drestapi):
    """
    This command create a Django project with or without Vue.js.
    """
    config = fs.read_config()

    proj_name = ctx.obj['proj_name']
    fs.check_path(ctx.obj['proj_name'], ctx.obj['path'], True)
    python_frameworksBasic_install()
    #install packages
    if packages == 'basic':
        os.system('pipenv install django')
        os.system(f'django-admin startproject {proj_name}')
        if frontend:
            os.system('pipenv install djangorestframework')
            os.chdir(os.path.join(config['current_project_dir'], proj_name))
            vue_init('frontend', ctx.obj['operatingsys'])

        if drestapi != None:
            os.system(f'pipenv install {drestapi}')
    else:
        os.system('pipenv install django')
        os.system(f'django-admin startproject {proj_name}')
        if frontend:
            os.system('pipenv install djangorestframework')
            os.chdir(os.path.join(config['current_project_dir'], proj_name))
            vue_init('frontend', ctx.obj['operatingsys'])

        if drestapi != None:
            os.system(f'pipenv install {drestapi}')
        #install user given packages
        for package in packages:
            os.system(f'pipenv install {package}')
    os.system(f'pipenv run pip freeze > {req}')
Example #2
0
def terminate():
    """
    Set yarn config file to null to be able to create another project.
    """
    config = fs.read_config()

    os.chdir(os.path.join(config['cli_dir'], const.CLI_NAME))
    terminate_proces()
    click.secho(('Yanr is deactivate from this project.'), fg=const.INFO_CLR)
Example #3
0
def terminate_proces():
    """
    set project_dir, current_project_dir and yanr_init to null when project added succesfully to git,
    then yanr can be reused to create another project
    """

    config = fs.read_config()
    fs.update_configFile('current_project_dir', None)
    fs.update_configFile('project_name', None)
    fs.update_configFile('yanr_init', False)
Example #4
0
def get_repo_name(repoName):
    config = fs.read_config()

    if repoName == None:
        repoName = config['project_name']
    elif config['project_name'] == None:
        repoName = click.prompt('Enter a repository name')
    else:
        repoName = repoName

    return repoName
Example #5
0
def global_config(username, password, projectdir):
    """
    Set your Github username, password  the directory where you want your projects to be stored as default
    so you don't have to do it anytime you create a new project. 
    """
    config = fs.read_config()
    if username != None and password != None and projectdir != None:
        fs.update_configFile('username', username)
        fs.update_configFile('password', password)
        fs.update_configFile('project_dir', projectdir)
    else:
        click.secho(('None of the option is given, see'), fg=const.INFO_CLR)
        click.secho(('yanr global_config --help'), fg=const.CMD_CLR)
        click.secho(('for more information'), fg=const.INFO_CLR)
Example #6
0
def main(name):
    click.echo(f'Welcom scripter, developer, programmer and automater {name}')
    config = fs.read_config()
        
    if config['cli_dir'] == None:
        while True:
            cli_path = click.prompt('Enter the path/to/proj_creator map')
            if os.path.exists(cli_path):
                click.secho(('Path added to config file, for any path changes see yanr global_confi --help'), fg=const.CMD_CLR)
                fs.update_configFile('cli_dir', cli_path)
                break
            else:
                click.secho((f'Directory {cli_path} don t exist'), fg=const.ERROR_CLR, bold=True)
    else:
        pass
Example #7
0
def delete_repo(ctx, reponame):
    """
    delete the given repository name from GitHub
        # reponame : Is an argument not optional, it has to be specified
    """
    if ctx.obj['username'] == None:
        user_name = click.prompt('GitHub username')
        gw.del_repo(user_name, ctx.obj['password'], reponame)
    else:
        gw.del_repo(ctx.obj['username'], ctx.obj['password'], reponame)

    config = fs.read_config()
    try:
        shutil.rmtree(os.path.join(config['current_project_dir'], '.git'))
        click.secho(('Git unlinked from project'), fg=const.INFO_CLR)
    except OSError as e:
        print('Directory not founded')
Example #8
0
def make_repo(browser, commit):
    create_btn = browser.find_element_by_xpath(
        '//*[@id="new_repository"]/div[3]/button')
    create_btn.click()
    config = fs.read_config()
    os.chdir(config['current_project_dir'])
    #add project to GitHub
    os.system('git init')
    os.system('git add .')
    os.system('git commit -m "first commit"')
    os.system('git remote add origin {}'.format(browser.current_url))
    os.system('git remote -v')
    os.system('git push -f origin master')
    os.chdir(os.path.join(config['cli_dir'], const.CLI_NAME))
    click.secho(('Project added succesfully to git'),
                fg=const.SUCCES_CLR,
                bold=True)
    time.sleep(5)
Example #9
0
def create_repo(ctx, repositoryname, readme, commit):
    """
    
    """
    config = fs.read_config()

    repository_name = gw.get_repo_name(repositoryname)

    if config['yanr_init'] and os.path.exists(config['current_project_dir']):
        # if ctx.obj['repoName'] == None or config['username'] == None and config['password'] == None:
        if config['username'] == None and config['password'] == None:
            # gw.git_automation(repository_name, ctx.obj['username'], ctx.obj['password'], readme, commit)
            if ctx.obj['username'] == None and ctx.obj['password'] == None:
                username_input = click.prompt('Github username')
                pass_input = click.prompt('Github password')
                gw.git_automation(repository_name, username_input, pass_input,
                                  readme, commit)
            elif ctx.obj['password'] == None and ctx.obj['password'] != None:
                username_input = click.prompt('Github username')
                gw.git_automation(repository_name, username_input,
                                  ctx.obj['password'], readme, commit)
            elif ctx.obj['password'] != None and ctx.obj['password'] == None:
                pass_input = click.prompt('Github password')
                gw.git_automation(repository_name, ctx.obj['username'],
                                  pass_input, readme, commit)
            else:
                gw.git_automation(repository_name, ctx.obj['username'],
                                  ctx.obj['password'], readme, commit)
        else:
            click.secho(('4'), fg=const.ERROR_CLR)
            gw.git_automation(repository_name, config['username'],
                              config['password'], readme, commit)
    else:
        click.secho(('None project initialize or project is deleted.'),
                    fg=const.ERROR_CLR,
                    bold=True)
        click.secho(('yanr terminate'), fg=const.INFO_CLR, bg='white')
        click.secho((
            'to create a new one in tthe case the project directory path is ot right or the project is deleted from. Your current project directory is: {} or see yanr create --help for more information'
            .format(config['current_project_dir'])),
                    fg=const.ERROR_CLR)
Example #10
0
def git_repo(ctx, username, password):
    """
    Add your project to GitHub
    \b
    git-repo commands optionals arguments
    \b
    add (create a new GitHub repository and add the project to it):
        # --repositoryname, -rn : let you choose a name for your new github repository, if you do't specify it the project name is used as name for the new repository
        
        # --readme, -rm         : Initialize your repository with a readme
        
        # --commit, -cm         : The first commit (default=First commit)
    \b
    del (delete the given repository name from GitHub):
        # reponame : Is an argument not optional, it has to be specified
    """
    ctx.ensure_object(dict)
    config = fs.read_config()

    # ctx.obj['repoName'] = repoName
    ctx.obj['username'] = username
    ctx.obj['password'] = password
Example #11
0
def create(ctx, proj_name, path, operatingsys):
    """
    \b
    create cmd optional arguments:
    \b
    -dj (create a django base project):
        # --packages, -p   : Install additional packages (max=2). See also yanr packages --help for more information about packages install
        
        # --req, -rq       : (default=requirements.txt)  pip freeze all your dependenties in a txt file, the default is requirements.txt, specify this option when you want another name. 
        
        # --frontend, -fr  : (default=False)  Install vue.js as frontend framework in django project if it is specify.  
        
        # --drestapi, -dra : Initialize the django project with a given restfull api framework.
    \b  
    -vue (create a vue.js base project):
        # No optional option
    \b
    -scrp (create a simple python scripting project):
        # No optional option
    """

    ctx.ensure_object(dict)  #send data to nested command
    config = fs.read_config()
    ctx.obj['operatingsys'] = operatingsys
    if config['yanr_init']:
        click.secho(
            ('The {} project is already initialized but not yet added to Git'.
             format(config['project_name'])),
            fg=const.INFO_CLR,
            bg='white')
        click.secho(('yanr git_repo --help for more information'.format(
            config['project_name'])),
                    fg=const.CMD_CLR)
        click.secho((
            'Or you have to terminate the ongoing proces to be able to create a new project.'
        ),
                    fg=const.INFO_CLR,
                    bg='white')
        click.secho(('yanr terminate --help for more information'),
                    fg=const.CMD_CLR)
        # user_input = click.prompt('Are you sure you don t want to add the current project to Git? [y/N]:')
        # if user_input == 'y':
        #     os.chdir(os.path.join(config['cli_dir'], const.CLI_NAME))
        #     terminate_proces()
        # elif user_input == 'N':
        #     sys.exit('See yanr git_repo --help for more detail')
        # else:
        #     click.secho(('Command don t exist'), fg=const.ERROR_CLR, bold=True)
        sys.exit()
    else:
        if path == None and config['project_dir'] == None:
            path = click.prompt(
                'Enter the path to the directory where you want the project to be stored'
            )
            fs.store_dataIn_configFile(ctx, path, proj_name)
            default_path = click.prompt(
                'Do you wanna use this path als defalt project path?[y/N')
            if default_path == 'y':
                fs.update_configFile('project_dir', path)
            else:
                pass
        elif config['project_dir'] != None:
            fs.store_dataIn_configFile(ctx, config['project_dir'], proj_name)
        elif path != None:
            fs.store_dataIn_configFile(ctx, path, proj_name)