Skip to content
Snippets Groups Projects
Commit 25c1e8b2 authored by María José Ramos's avatar María José Ramos
Browse files

Upload all files

parent b43f6471
No related branches found
No related tags found
No related merge requests found
Showing
with 433 additions and 1 deletion
...@@ -22,7 +22,7 @@ The requirements in the ```requirements.sh``` file correspond to certain python ...@@ -22,7 +22,7 @@ The requirements in the ```requirements.sh``` file correspond to certain python
To install the requirements, open the terminal and execute the following commands: To install the requirements, open the terminal and execute the following commands:
Change directory: Change directory:
``` cd git_zenodo_tutorial``` ``` cd git_zenodo_assistant```
Run the requirements file to install the libraries: ``` sh requirements.sh ``` Run the requirements file to install the libraries: ``` sh requirements.sh ```
......
def git_review():
# Tools
import tkinter as tk
import tkinter.ttk
# Messages for windows
message0 = """
Git is more than a website, Git is a control version software, which is
a software made for tracking changes in any set of files in a directory.
Managing changes of your documents, data, notebooks and coding scripts is
essential when you do research.\n
As you probably have learned by now, just copying your files and renaming
them as "myProjectUpdateFinalTrueFinalPrint.ipynb" is not the most
efficient way to do so. Git makes it easier by providing an online
plataform for Version Control of personal and collaborative projects.
"""
message1 = """
The Git software stores and save files to a directory called repository,
also shorten as repo. A Git repository allows various operations to create
different versions of the files in it.\n
A Git repository can be local (placed in your computer) or remote
(hosted on the Internet, or in a different server).\n
By installing git to your computer, and creating a GitHub or GitLab
account you can start your Version Control with git.
"""
message2 = """
From Github or Gitlab you can Fork and Clone repositories.\n
A git fork is an operation of copying a repository to your git account.\n
A git clone is an operation of copying a repository to your local machine.\n
Maybe you knew all of this already. In fact, you probably have this program
running because you did a git clone to your computer (or Virtual Machine,
for that matter).\n
One more thing before you continue: remember than you can only push to git
repositories where you have permissions to do so. If you need to clone a
repo that you do not own and need to make changes, fork the repo first and
then you can clone it.
"""
message3 = """
You can obtain a Git repository by either cloning a Git repository
or by converting a local directory to a Git repository, using git init.\n
It does not matter if the directory is a new local directory, or an
already existent local directory, the command git init works in both
cases.\n
And you can also git init a git repository, is it safe to do so,
it will not overwrite files that are already there.
"""
message4 = """
Git push is an operation to publish new local commits on a remote server.\n
When you want to update your changes (could be a new file in the directory,
or a change in an already existing file)to your Git account, you need to git
push.\n
But before a git push, you have to git add (to add your new or modified
files to your git repo), git commit (to save these changes) and then you
can execute your git push command.\n
There could be more commands that you need to execute before a git push.
This is only a basic review, and although the tutorial will include some new
steps. You can learn more in the documentation and you should.
"""
# Creating window
root = tk.Tk()
root.title("Review of Git")
root.geometry("250x200")
root.config(background = "#F5F5F5")
root.eval('tk::PlaceWindow . center')
label = tk.Label(root, text ="Select an option and\n review some concepts")
label.pack(pady = 10)
# Open window functions
def open_window_0():
window_0 = tk.Toplevel(root)
window_0.title("Git and Version Control")
window_0.geometry("530x200")
window_0.config(background = "#F5F5F5")
# Texts
title = tk.Label(window_0, text ="\n\nWhat is Git?", bg= "#F5F5F5").pack()
text = tk.Label(window_0, text =message0, bg= "#F5F5F5", anchor="e", justify="left", width=100).pack()
return
def open_window_1():
window_1 = tk.Toplevel(root)
window_1.title("Git Repository")
window_1.geometry("540x200")
window_1.config(background = "#F5F5F5")
title = tk.Label(window_1, text ="\n\nWhat is a Git repository?", bg= "#F5F5F5").pack()
text = tk.Label(window_1, text = message1, bg= "#F5F5F5", anchor="e", justify="left", width=100).pack()
return
def open_window_2():
window_2 = tk.Toplevel(root)
window_2.title("git fork/git clone")
window_2.geometry("550x250")
window_2.config(background = "#F5F5F5")
title = tk.Label(window_2, text ="\n\nWhat does a git fork/git clone do?", bg= "#F5F5F5").pack()
text = tk.Label(window_2, text =message2, bg= "#F5F5F5", anchor="e", justify="left", width=100).pack()
def open_window_3():
window_3 = tk.Toplevel(root)
window_3.title("git init")
window_3.geometry("510x200")
window_3.config(background = "#F5F5F5")
title = tk.Label(window_3, text ="\n\nWhat does a git init do?", bg= "#F5F5F5").pack()
text = tk.Label(window_3, text =message3, bg= "#F5F5F5", anchor="e", justify="left", width=100).pack()
return
def open_window_4():
window_4 = tk.Toplevel(root)
window_4.title("git add/git commit/git push")
window_4.geometry("560x230")
window_4.config(background = "#F5F5F5")
title = tk.Label(window_4, text ="\n\nGit push and the previous steps", bg= "#F5F5F5").pack()
text = tk.Label(window_4, text =message4, bg= "#F5F5F5", anchor="e", justify="left", width=100).pack()
return
# Buttons that open windows and destroy the root window.
button_0 = tk.Button(root, text ="Git and Version Control", bg="#B0E0E6", command=open_window_0)
button_0.pack(side="top")
button_1 = tk.Button(root, text= "Git Repository", bg="#B0E0E6", command=open_window_1)
button_1.pack(side="top")
button_2 = tk.Button(root, text= "git fork/git clone", bg="#B0E0E6", command=open_window_2)
button_2.pack(side="top")
button_3 = tk.Button(root, text ="git init", bg="#B0E0E6", command=open_window_3)
button_3.pack(side="top")
button_4 = tk.Button(root, text= "git add/git commit/git push", bg="#B0E0E6", command=open_window_4)
button_4.pack(side="top")
button_done = tk.Button(root, text = "Done", bg="#FF6347", command=root.destroy)
button_done.pack(side="bottom")
# mainloop, runs infinitely, unless root.destroy
root.mainloop()
return
def path_input():
# Tools
import tkinter as tk
from tkinter import filedialog
from termcolor import colored, cprint
# Function to select directory and store path
def select_dir():
done = colored('Done', 'red')
global path
path = tk.filedialog.askdirectory()
print(f"Selected directory: {path}\n"
f"\nClick {done} or change your selection.\n")
return
# Creating window
root = tk.Tk()
root.title("File browser")
root.geometry("250x60")
root.config(background = "#F5F5F5")
root.eval('tk::PlaceWindow . center')
# Buttons that execute the function and destroy the loop
button_explore = tk.Button(root, text="Explore", bg="#B0E0E6", command=select_dir)
button_done = tk.Button(root, text = "Done", bg="#FF6347", command=root.destroy)
button_explore.pack(side="top")
button_done.pack(side="top")
root.mainloop()
return path
# Tools
import os
import time
from termcolor import colored, cprint
from git_assistant.git_tools.git_search import path_input
from git_assistant.git_tools.git_more import git_review
# Hello world
git = colored('Git', 'cyan')
enter = colored('Enter', 'cyan')
init = colored('init', 'cyan')
fork = colored('fork', 'cyan')
clone = colored('clone', 'cyan')
add = colored('add', 'cyan')
allfiles = colored('--all', 'cyan')
log = colored('log', 'cyan')
commit = colored('commit', 'cyan')
push = colored('push', 'cyan')
remote = colored('remote add origin', 'cyan')
select = colored('Select', 'cyan')
submit = colored('Submit', 'cyan')
explore = colored('Explore', 'cyan')
done = colored('Done', 'red')
password = colored('password', 'cyan')
token = colored('token', 'cyan')
gitlab = colored('GitLab', 'cyan')
github = colored('GitHub', 'cyan')
copy = colored("COPY", "green", attrs=['reverse'])
paste = colored("PASTE", "green", attrs=['reverse'])
welcome_message = f"""
Hello! Welcome to this {git} tutorial, where you will upload a file to
your {git} remote repository, and learn some basic commands of git to
type them in the terminal the next time, without using this program.\n
Here, you will have to paste the URL of your {git} repository, provide the name
of the file you want to upload, a commit message and finally, your username and
password/token. You will not execute the commands yourself, the programm will do it
for you.
"""
print(welcome_message)
input(f"When you are ready, press {enter} to start and learn about {git}.")
more_message = f"""
This tutorial is not intented to teach you ALL about git, but to help
you to {git} {add}, {git} {commit} and {git} {push} a file to your git
repository by teaching some important things along the way.\n
You do not have to understand it all by the end, altough we hope
that if one day you need to {git} {remote}, you will remember
that you saw it here first.\n
Before starting the tutorial, you should already be a little bit
familiarized with {git}. If you are not, do not worry. We have created
a review of some important concepts, in case you need it.
"""
print(more_message)
input(f"Press {enter} to see the review. Click {done} when you finish.")
git_review()
input(f"Excellent! Let's start the tutorial. Press {enter}")
browser_message = f"""
Before executing your {git} commands, you should be located (pwd) in the
directory that you want to {git} {init}, {git} {push}, etc... This is, you
should change directories (cd). But you will not need to exit the program!
Let me help you to do it.
"""
print(browser_message)
input(f"Press {enter} to open the Directory Browser to {select} and {submit} the "
"path of the directory that you want.\n")
open_browser = True
while open_browser == True:
try:
git_path = path_input()
break
except:
print(f"You did not {submit} any directory. Try again: click {explore}, pick your directory and then {done}.\n")
try:
git_path = path_input()
break
except:
print(f"You did not {submit} any directory. Try again: click {explore}, pick your directory and then {done}.\n")
open_browser = True
input(f"The path to your directory has been stored. Press {enter} to continue.\n")
print("Changing directory...\n")
time.sleep(2)
os.chdir(git_path)
input(f"Done! Press {enter} to continue.\n")
# Git init
init_message = f"""
If you try to execute {git} commands in a non-git directory, you will
encounter a fatal error: not a git repository.\n
To avoid this error, first you have to {git} {init}. And if, by accident,
your directory was already a {git} repository, there is no problem,
it wil not overwrite anything.
"""
print(init_message)
cprint("command0: git init ", "green")
input(f"\nPress {enter} to execute your command...")
os.system("git init")
# Remove origin
rm_message = f"""
A {git} remote origin is the name for the remote repository of a {git}
directory. If you try to execute {git} commands in the wrong remote
repository, you will encounter errors. To make sure this do not
happen while running the tutorial, we are going to remove the previous
origin.
"""
print(rm_message)
cprint("command1: git remote rm origin ", "green")
input(f"\nPress {enter} to execute your command...")
os.system("git remote rm origin")
# Add origin
origin_message = f"""
Now, let's add a new origin. You will need to provide the url of the
{git} repo where you want to you {git} {push}.
"""
print(origin_message)
url = input(str(f"Paste the url of your {git} repository: "))
print(f"Please, check the url: {url}\n")
url_answer = input(str("Is that the right url? y/n: "))
while url_answer != "y":
if url_answer == "n":
url = input(str(f"\nNo problem! Let's try again\nPaste the url of your {git} repository: "))
print(f"Please, check the url: {url}\n")
url_answer = input(str("Is that the right url? y/n: "))
else:
print("\nInvalid option. Try again.\n")
print(f"Please, check the url: {url}\n")
url_answer = input(str("Is that the right url? y/n: "))
if url_answer == "y":
print(f"Excellent!\n. To {add} the origin we will use the next command.\n")
cprint(f"command2: git remote add origin {url}", "green")
input(f"\nPress {enter} to execute the command...")
os.system(f"git remote add origin {url}")
# Check the new origin
print("\nAnd you can check the new origin by doing: \n")
cprint("command3: git remote -v ", "green")
input(f"\nPress {enter} to execute the command...")
os.system("git remote -v")
# Git status
status_message = f"""
{git} status shows the current state of your {git} working directory
and staging area. Green shows file is in {git} repository and
committed with latest changes. Red shows file is in {git} repository
but latest changes has not been committed. If you do not {add} the
red files before committing, these files will not be included in
your {commit}.
"""
print(status_message)
cprint("command4: git status", "green")
input(f"\n{press} Enter to execute the command...")
os.system("git status")
# Git add
print(f"\nTo {git} {add}, you have to pick a file in red from the list above and copy the name.")
file = input(str("Paste the name of your file and do not forget the extension (example.ipynb)\n"
"or type {allfiles} to add all the files in the directory: "))
print(f"Please, check the name of your file: {file}\n")
file_answer = input(str("Is that the right name and extension? y/n: "))
while file_answer != "y":
if file_answer == "n":
file = input(str(f"\nNo problem! Let's try again.\n"
f"Paste the name of the file (example.ipynb) or type {allfiles}: "))
print(f"Please, check the name of your file: {file}\n")
file_answer = input(str("Is that the right name and extension? y/n: "))
else:
print("\nInvalid option. Try again.\n")
print(f"Please, check the name of your file: {file}\n")
file_answer = input(str("Is that the right name and extension? y/n: "))
if file_answer == "y":
print("Excellent!\n By adding a new file, you choose which changes you want to save\n")
cprint(f"command5: git add {file}", "green")
input(f"\nPress {enter} to execute the command...")
os.system(f"git add {file}")
# Git commit
print(f"\nWhen you {commit}, you save these changes. To identify these changes, you can write a {commit} message")
commit = input(f"Type a {commit} message. Make it short and simple: ")
cprint("command6: git commit -m", "green")
input(f"\nPress {enter} to execute the command...")
os.system(f"git commit -m {commit}")
# Git log
print(f"\nAnd you can see the record of commits that you have done using {git} {log}.")
cprint("command6: git log", "green")
input(f"\nPress {enter} to execute the command...")
os.system("git log")
# Git push
push_message = f"""
Finally, {push} to your repository by executing the next command. Note that
you will need to enter your {git} username and password/token. Do not worry if
you do not see your password in the console when you type it!
It is to protect your data.\n
To access your {gitlab} account, you need your {password}.\n
To access your {github} account, you need a {token}.\n
You can generate a token by logging in to your {git} account
and going into this page:
{colored('https://github.com/settings/tokens', 'cyan')}\n
Select only the repo scopes.\n
Remember to {copy} the token so you can {paste} it here.
Press {enter} when you are ready.
"""
input(push_message)
cprint(f"command6: git push {url}", "green")
input(f"\nPress {enter} to execute the command...")
os.system(f"git push {url}")
# Check the git push
print(f"Go to:\n{url}\nto see if the {push} was successful.")
push_answer = input(str("Has your file been pushed correctly? y/n: "))
while push_answer =="n":
push_error = input(str("\nYou probably had an Authentication Error.\n Do you want to:\n"
f"a) try to {push} again?\n"
"b) Exit and try the tutorial later?\n"))
if push_error == "a":
cprint(f"command6: git push {url}", "green")
input(f"\nPress {enter} to execute the command...")
os.system(f"git push {url}")
print(f"Go to:\n{url}\nto see if the {push} was successful.")
push_answer = input(str("Has your file been pushed correctly? y/n: "))
elif push_error == "b":
push_answer = "y"
# End of tutorial
if push_answer == "y":
print("\nAlright! You have reached the end of this tutorial.\n")
images_tutorial/git001.png

16.1 KiB

images_tutorial/git002.png

25.9 KiB

images_tutorial/git003.png

34.3 KiB

images_tutorial/git004.png

91.1 KiB

images_tutorial/git005.png

69.5 KiB

images_tutorial/git006.png

6.79 KiB

images_tutorial/git007.png

70.6 KiB

images_tutorial/git_image.png

211 KiB

images_tutorial/repo_image.png

148 KiB

images_tutorial/zenodo001.png

129 KiB

images_tutorial/zenodo002.png

51.6 KiB

images_tutorial/zenodo003.png

53.3 KiB

images_tutorial/zenodo_image.png

281 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment