示例#1
0
    def create_remote_repo(self):
        git = Github(self.usr_name, self.usr_pwd).get_user()

        try:
            git.create_repo(self.repo_name, private=self.is_private)
            self.initialize_git()
        except GithubException as err:
            self.pretty_print.warning(err)
            choice = input(
                '\nIt seems that you have entered wrong username or password. Do you wants to see and change your username and password credentials? (y/n) '
            )
            if (choice.strip() == 'y'):
                chdir(credentials_dir)
                Popen('nano {}'.format('credentials.json'), shell=True).wait()
                self.usr_name = self.get_credentials()['usr']
                self.usr_pwd = self.get_credentials()['pwd']
                self.create_remote_repo()
            else:
                exit()
        except exceptions.ConnectionError:
            self.pretty_print.fail(
                "Failed to connect to GitHub. Please make sure you're conneccted to the internet."
            )
        except exceptions.Timeout as err:
            self.pretty_print.fail(err)
            self.pretty_print.warning('Attempting to reconnect...')
            self.create_remote_repo()
示例#2
0
def project_init():
    if len(sys.argv) == 2:
        folderName = str(sys.argv[1])
        os.makedirs(home_path + folderName)  # Create a new directory

        # Create a git repository
        os.chdir(home_path + folderName)
        os.system('git init')

        # Create a readme file and do an Inital commit
        os.system('echo "# ' + folderName + '" >> README.md')
        os.system('git add .')
        os.system('git commit -m "Initial commit"')

        g_hub = Github(
            access_token).get_user()  # Login using Personal Access Token
        g_hub.create_repo(folderName)  # Create repository in Github

        os.system('git remote add origin [email protected]:' + git_user + '/' +
                  folderName + '.git')
        os.system('git push -u origin master')
    else:
        print("Need a name for the Project...Exiting")
        return

    return
示例#3
0
def create():
    path = "projects/"
    folder_name = str(sys.argv[1])
    if not os.path.exists(path + folder_name):
        os.makedirs((path + folder_name), 0o0777)
        user = Github(sys.argv[2]).get_user()
        user.create_repo(folder_name)
示例#4
0
def createpj(pjName):
    """
    1. create a new remote git repository on github
    2. make a new project folder
    3. initialize local git repository and push
    :param pjName: str new project name
    :return pjpath: str  path for new project
    """
    load_dotenv(dotenv_path=Path(os.getenv('CREATEPJ_HOME')) / '.env')
    user = Github(os.getenv('GITHUB_USERNAME'),
                  os.getenv('GITHUB_PASSWORD')).get_user()
    user.create_repo(pjName)
    pjpath = Path(os.getenv("MYPROJECTS_HOME")) / pjName
    os.mkdir(pjpath)
    open(pjpath / 'README.md', 'a').close()
    open(pjpath / '.gitignore', 'a').close()
    git.Repo.init(pjpath)
    localRepo = git.Repo(pjpath)
    localRepo.index.add(['README.md', '.gitignore'])
    localRepo.index.commit('initial commit')
    origin = localRepo.create_remote(
        'origin', '[email protected]:' + os.getenv('GITHUB_USERNAME') + '/' +
        pjName + '.git')
    origin.push('master', u=True)

    return pjpath
示例#5
0
def create():
    projectName = str(sys.argv[1])
    os.makedirs(path + str(projectName))
    print("\nProject " + projectName + " folder created on path " + path)
    account = Github(un, pw).get_user()
    account.create_repo(projectName)
    print("Repository " + projectName + " added to GitHub")
    print("")
示例#6
0
def create():
    folder_name = str(sys.argv[1])
    os.makedirs(path+folder_name)

    user = Github(git_Username, git_Password).get_user()

    user.create_repo(folder_name, private=True)

    print("successfully created repository {}".format(folder_name))
示例#7
0
def create_repository(project_name: str, git_username: str, git_password: str):
    user = Github(git_username, git_password).get_user()

    if private:
        print("Creating private repository...")
    else:
        print("Creating public repository...")

    user.create_repo(project_name, private=private)
    print("Succesfully created repository " + project_name)
def create_github_repo():
    foldername = str(sys.argv[1])
    accessToken = str(sys.argv[2])
    try:
        if not os.path.exists(foldername):
            os.makedirs(foldername)
            user = Github(accessToken).get_user()
            user.create_repo(foldername)
    except:
        pass
示例#9
0
def create():
    # Chane working directory for script to project directory
    os.chdir(path)

    # Make new porject folder in directory
    os.makedirs(project_name)

    # Make project repository
    user = Github(username, password).get_user()
    user.create_repo(name=project_name,
                     private=string_to_bool(is_repo_private))
    print("Succesfully created repository {}".format(project_name))
示例#10
0
def start_repo():
    project_name = sys.argv[1]
    user = Github(USER, TOKEN).get_user()

    try:
        user.create_repo(project_name)

    except Exception:
        print(Exception)

    finally:
        print("Successfully created repository!")

    return
示例#11
0
def new_folder_repo():
    fol_name = str(sys.argv[1])
    pubpriv = str(sys.argv[2])
    os.makedirs(PATH + "/" + fol_name)

    user = Github(username, password).get_user()

    if (pubpriv == "private"):
        user.create_repo(fol_name, private=True)
    if (pubpriv == "public"):
        user.create_repo(fol_name, private=False)

    print("")
    print("Created repository and directory with name" + fol_name)
    def create_repo_online(self):
        try:
            user = Github(self.github_token).get_user()
            logger.info(
                f' Authenticated GitHub user "{user.login}": Creating new GitHub repository {self.project_name}\n'
            )
            user.create_repo(self.project_name)
        except Exception as e:
            logger.exception(
                f""" WARNING: Check error message below for details - Most likely caused by Invalid credentials (github token) being provided. Check the .env file for typos and confirm whether the github token provided has the necessary permissions.
            Required Permissions: repo, repo:status, repo_deployment, public_repo, security:events\n"""
            )

            sys.exit(1)
示例#13
0
def create():
    # changes directory to 'D' drive, where i have my checkouts, comment this out if you save in the 'C' drive
    os.chdir("d:")

    folderName = str(sys.argv[1])

    if os.path.exists(path + folderName):
        print('Path already exists')
        exit(1)
    else:
        os.makedirs(path + str(folderName))

    user = Github(username, password).get_user()
    user.create_repo(folderName)
    print("Successfully created repository {}".format(folderName))
示例#14
0
def create_folder_and_repo():
    folder_name = str(sys.argv[1])
    public_private = str(sys.argv[2])
    os.makedirs(path + folder_name)

    user = Github(git_username, git_password).get_user()

    if (public_private == "private"):
        print('PRIVATE')
        user.create_repo(folder_name, private=True)
    else:
        print('PUBLIC')
        user.create_repo(folder_name)

    print("Succesfully created repository {}".format(folder_name))
def create():
	repositoryName = str(sys.argv[1])

	try:
		# Create target Directory
		os.mkdir(path + repositoryName)
		print("\n... > Local directory " + repositoryName + " succesfully created.\n")
	except OSError as err:
		print("\n... > !Local directory " +  repositoryName + " already exists\n")
	
	# Create a GitHub instance
	user = Github(username, password).get_user()
	user.create_repo(repositoryName)

	print("\n... > GitHub repo: {} successfully created\n".format(repositoryName))
示例#16
0
文件: create.py 项目: imkaka/gnit
def create(folderName):
    os.makedirs(path + folderName)

    user = Github(TOKEN).get_user()
    repo = user.create_repo(folderName)

    print("Succesfully created repository {}".format(folderName))
def create():
    folderName = str(input("Give the name of the project folder and repo: "))
    # folderName = str(sys.argv[1])
    os.makedirs(path + str(folderName))
    user = Github(username, password).get_user()
    repo = user.create_repo(folderName)
    print("Succesfully created repository {}".format(folderName))
示例#18
0
def create():
    folderName = str(sys.argv[1])
    os.makedirs(path + str(sys.argv[1]))
    user = Github(username, password).get_user()
    repo = user.create_repo(sys.argv[1])
    print("Succesfully created repository {}".format(sys.argv[1]))
    print("Hello")
示例#19
0
def make():
    """
    Create a Github repository at specified path

    Parameters:
    None

    Returns:
    None
    """

    #project name given as first argument after calling shell script
    project_name = str(sys.argv[1])
    #create a directory for the repo
    os.makedirs(path + project_name)

    if not os.path.isdir(path + project_name):
        print("Directory {} not created".format(project_name))
        return

    #create instance of your account using username and password
    user_account = Github(username, password).get_user()
    #create a repo with project name
    repository = user_account.create_repo(project_name)
    print("Sucessfully created repository {}".format(project_name))

    return
示例#20
0
def create():
    folderName = str(sys.argv[1])
    os.makedirs(path + str(folderName))
    user = Github(username, password).get_user()

    private = True
    while True:
        isPrivatePrompt = input("Create private repository (y/N):")
        if isPrivatePrompt.startswith("y") or isPrivatePrompt.startswith("Y"):
            private = True
        elif isPrivatePrompt.startswith("n") or isPrivatePrompt.startswith(
                "N"):
            private = False
        else:
            private = None

        if private is not None:
            break

    description = input('Project description:')

    repo = user.create_repo(folderName,
                            private=private,
                            description=description)
    print("Succesfully created repository {}".format(folderName))
def CreateGitHubRepo():
    global repoName
    global username
    global password
    GetCredentials()
    try:
        user = Github(username, password).get_user()
        user.create_repo(repoName)
        return True
    except Exception as e:
        username = ""
        password = ""
        print(bcolors.FAIL)
        print(e)
        print(bcolors.ENDC)
        return False
示例#22
0
def create():
    folderName = str(sys.argv[1])
    newPath = str(path) + str(folderName)
    os.mkdir(newPath)
    user = Github(username, password).get_user()
    repo = user.create_repo(sys.argv[1])
    print("Succesfully created repository {}".format(sys.argv[1]))
示例#23
0
def create():
    path = "E:/projects/"
    username = input('Enter your github username: '******'Enter your github password: '******'Make the repo private?(y/n): ')
        if private not in ['y', 'Y', 'n', 'N']:
            print('Please enter y or n')
        else:
            if private in ['y', 'Y']:
                private = True
            else:
                private = False
            break

    folderName = str(sys.argv[1])
    os.makedirs(path + str(folderName))
    try:
        user = Github(username, password).get_user()
        repo = user.create_repo(folderName, private=private)
        print(f"Succesfully created repository {folderName}")

        os.chdir(path + str(folderName))
        os.system('echo # ' + str(folderName) + ' >> README.md')
        os.system('git init')
        os.system('git add README.md')
        os.system('git commit -m "added README"')
        os.system(
            str("git remote add origin https://github.com/" + username + "/" +
                str(folderName) + ".git"))
        os.system('git push -u origin master')
    except:
        print('An error was encountered')
def create():
    folderName = path + str(sys.argv[1])
    print("Creating folder{}".format(folderName))
    os.makedirs(folderName)
    user = Github(token).get_user()
    repo = user.create_repo(sys.argv[1], private=True)
    print("Succesfully created private repository {}".format(sys.argv[1]))
示例#25
0
def create(x, username, password):
	# Get Github account and create repo named after the project.
	try:
		user = Github(username, password).get_user()
		repo = user.create_repo(x)

	except:
		print("Wrong login details, try again!")
		github(x)

	# Create folder and README.md file on the local system.

	os.makedirs(path+(str(x)))
	os.chdir(path+(str(x)))


	commands = ["git init &", "touch README.md &", "git remote add origin https://github.com/joshlewis-py/" 
		    + x + ".git &", "git add . &", 'git commit -m "Generated README.md"]
	
	
	for command in commands:
		os.system(command)
		# os.system('echo '+ command)
		time.sleep(1)
	exit()
示例#26
0
def create():
    folderName = str(sys.argv[1])
    os.makedirs(path + str(folderName))
    user = Github(username, password).get_user()
    repo = user.create_repo(folderName)
    # f strings
    print(f"Succesfully created repository {folderName}")
示例#27
0
def create():
    """Skrypt w pierwszej kolejności tworzy folder z podanych argumentów podczas uruchamiania.
    Jeśli jednak nie podano, to nazwę bierze z domyślnej wartości ze zmiennej folder.
    Następnie inicjuje repozytorium git, tworzy na githubie repo z nazwą folderu, 
    tworzy plik README.md i wysyła.
    Na koniec tworzy pusty plik pythona i uruchamia Visual Code z tym folderem.
    Dzięki dodaniu do path w windows, jest możliwe uruchomienie z każdego miejsca w systemie poleceniem:
    <nazwa_skryptu.py> <nazwa_projektu>
    """
    folder = "Projekt_X"
    if len(sys.argv) > 1:
        folder = sys.argv[
            1]  # jeżeli podano argument przy uruchomieniu, nadaje nim nazwę folderu
    path = init_path + folder
    os.mkdir(path)
    os.chdir(path)
    user = Github(username, password).get_user()
    repo = user.create_repo(folder)
    os.system("git init")
    os.system(
        "git remote add origin https://github.com/UZYTKOWNIK/{}.git".format(
            folder))
    with open("README.md", "w") as f:
        f.write("### " + folder)
    os.system("git add .")
    os.system('git commit -m "initial commit"')
    os.system("git push -u origin master")
    open("main.py", "w").close()
    os.system("code .")
示例#28
0
def create_project():
    """Function makes a local repo for project in workspace directory and also creates an online repository on Github 
    for the specified account"""

    # Access user account and make repo online
    try:
        status = os.makedirs(workspace + sys.argv[1])
        user = Github(username, password).get_user()
        if user.create_repo(
                sys.argv[1]
        ):  #Repo will be created on Github through conditional check here
            print(
                f"Successfully created local directory in workspace and remote repository - {sys.argv[1]} - on Github"
            )
        else:
            print(f"Unable to create remote repository {sys.argv[1]}")

    except FileExistsError:
        print(
            "Project with same name exists on system workspace directory.\nPlease try again."
        )

    except GithubException as e:
        if e.status == 422:
            print(
                "Repository with same name already exists on this account.\nPlease try again."
            )
        elif e.status == 401:
            print(
                "Invalid login credentials. Please check username or password specified in localNav script."
            )

        # Following line will only execute if Github error occurs but, the directory was still made in workspace directory
        os.rmdir(workspace + sys.argv[1])
示例#29
0
文件: create.py 项目: craiglobo1/git
def create():
    folderName = str(sys.argv[2])
    os.makedirs(os.path.join(path, folderName))
    md = open(os.path.join(path, folderName) + r'\README.md', 'w')
    md.close()
    user = Github(username, password).get_user()
    repo = user.create_repo(folderName)
    print("Succesfully created repository {}".format(folderName))
示例#30
0
def CreateGitHubRepo():
    global repoName
    global private
    global username
    global password
    GetCredentials()
    try:
        user = Github(username, password).get_user()
        user.create_repo(repoName, private=private)
        return True
    except Exception as e:
        repoName = ""
        username = ""
        password = ""
        private = ""
        print(Fore.RED + str(e) + Fore.WHITE)
        return False
示例#31
0
文件: views.py 项目: tasnim07/GitApp
def create_repo(request):
	if request.method == 'GET':
		return render(request, 'app/create_repo.html')

	user = request.user
	
	repo_name = request.POST.get('repo_name')
	description = request.POST.get('description')
	
	access_token = GitHubUser.objects.get(user=user).access_token
	github_user = Github(login_or_token=access_token).get_user()
	new_repo = github_user.create_repo(repo_name, description=description)
	return redirect(reverse('get-repo'))