Dateien nach "/" hochladen

This commit is contained in:
M_Viper 2024-02-20 10:47:54 +00:00
parent 8e882504ca
commit bd188bd77d
2 changed files with 172 additions and 2 deletions

View File

@ -1,2 +1,52 @@
# Python_Gitea_Upload
# git_upload
<div align=center>
<a href="https://m-viper.de">
<img width=566 align="center" src="https://m-viper.de/img/welcome-banner.gif" />
</a>
</div>
<h1 align="center">👋 Hey! schön dich zu sehen</h1>
<h3 align="center">Wilkommen auf meiner Seite! Ich bin M_Viper und komme aus Burghausen</h3>
### Languages
![Python](https://img.shields.io/badge/-Python-000?&logo=Python)
![JavaScript](https://img.shields.io/badge/-JavaScript-000?&logo=JavaScript)
![C](https://img.shields.io/badge/-C-000?&logo=C)
![Java](https://img.shields.io/badge/-Java-000?&logo=Java&logoColor=007396)
![TypeScript](https://img.shields.io/badge/-TypeScript-000?&logo=TypeScript)
![C++](https://img.shields.io/badge/-C++-000?&logo=c%2b%2b&logoColor=00599C)
![SQL](https://img.shields.io/badge/-SQL-000?&logo=MySQL)
![Swift](https://img.shields.io/badge/-Swift-000?&logo=Swift)
### Technologies
![AWS](https://img.shields.io/badge/-AWS-000?&logo=Amazon-AWS&logoColor=F90)
![Docker](https://img.shields.io/badge/-Docker-000?&logo=Docker)
![Kubernetes](https://img.shields.io/badge/-Kubernetes-000?&logo=Kubernetes)
![Linux](https://img.shields.io/badge/-Linux-000?&logo=Linux)
![Node.js](https://img.shields.io/badge/-Node.js-000?&logo=node.js)
![PyTorch](https://img.shields.io/badge/-PyTorch-000?&logo=PyTorch)
![React](https://img.shields.io/badge/-React-000?&logo=React)
![Redis](https://img.shields.io/badge/-Redis-000?&logo=Redis)
![Spring](https://img.shields.io/badge/-Spring-000?&logo=Spring)
![TensorFlow](https://img.shields.io/badge/-TensorFlow-000?&logo=TensorFlow)
### Cybersecurity Projects
[![](https://img.shields.io/badge/-🩸%20Heartbleed-000)](#)
[![](https://img.shields.io/badge/-🌊%20SYN%20Flood-000)](#)
[![](https://img.shields.io/badge/-🗂%20Packet%20Sniffing%20%26%20Spoofing-000)](#/Packet-Sniffing-and-Spoofing)
[![](https://img.shields.io/badge/-💉%20SQL%20Injection-000)](#)
[![](https://img.shields.io/badge/-🛡%20Spectre%20%26%20Meltdown-000)](#)
[![](https://img.shields.io/badge/-🌐%20Network%20Tools-000)](#)
### Folge mir:
[![website](https://m-viper.de/img/globe-light.svg)](https://m-viper.de)
[![website](https://m-viper.de/img/globe-dark.svg)](https://m-viper.de)
&nbsp;&nbsp;
[![website](https://m-viper.de/img/youtube-light.svg)](https://www.youtube.com/@M_Viper)
[![website](https://m-viper.de/img/youtube-dark.svg)](https://www.youtube.com/@M_Viper)
&nbsp;&nbsp;

120
git.py Normal file
View File

@ -0,0 +1,120 @@
import os
import base64
import requests
import subprocess
def repository_exists(repo_url, token, repo_name):
headers = {
'Authorization': f'token {token}',
'Content-Type': 'application/json',
}
response = requests.get(f'{repo_url}/api/v1/user/repos', headers=headers)
repos = response.json()
for repo in repos:
if repo['name'] == repo_name:
return True
return False
def create_repository(repo_url, token, repo_name):
headers = {
'Authorization': f'token {token}',
'Content-Type': 'application/json',
}
response = requests.post(f'{repo_url}/api/v1/user/repos', headers=headers, json={'name': repo_name})
if response.status_code == 201:
print(f"Repository '{repo_name}' created successfully.")
return True
else:
print(f"Failed to create repository '{repo_name}'.")
return False
def add_mit_license(local_path, language='english'):
mit_license_text_english = """
MIT License
Copyright (c) 2024 [Name]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
mit_license_text_german = """
MIT-Lizenz
Urheberrecht (c) 2024 [Name]
Hiermit wird unentgeltlich jeder Person, die eine Kopie der Software und der
zugehörigen Dokumentationsdateien (die "Software") erhält, die Erlaubnis erteilt,
sie uneingeschränkt zu nutzen, inklusive und ohne Ausnahme mit dem Recht, sie zu verwenden,
zu kopieren, zu ändern, zusammenzufügen, zu veröffentlichen, zu verbreiten, zu unterlizenzieren
und/oder zu verkaufen, und Personen, denen diese Software überlassen wird, diese Rechte zu gewähren,
unter den folgenden Bedingungen:
Der obige Urheberrechtsvermerk und dieser Erlaubnisvermerk sind in allen Kopien oder
wesentlichen Teilen der Software beizulegen.
DIE SOFTWARE WIRD "WIE BESEHEN" OHNE JEGLICHE AUSDRÜCKLICHE ODER IMPLIZIERTE GARANTIEN, EINSCHLIESSLICH
DER GARANTIE DER MARKTFÄHIGKEIT, DER EIGNUNG FÜR EINEN BESTIMMTEN ZWECK UND DER NICHTVERLETZUNG VON
RECHTEN DRITTER, BEREITGESTELLT. IN KEINEM FALL HAFTEN DIE AUTOREN ODER COPYRIGHT-INHABER FÜR JEGLICHEN
SCHADEN ODER SONSTIGE ANSPRÜCHE, OB AUS EINEM VERTRAG, EINER UNERLAUBTEN HANDLUNG ODER ANDERWEITIG,
DER SICH AUS, IN ODER IN VERBINDUNG MIT DER SOFTWARE ODER DER VERWENDUNG ODER ANDEREN GESCHÄFTEN IN
DER SOFTWARE ERGIBT.
"""
mit_license_path = os.path.join(local_path, 'LICENSE')
mit_license_text = mit_license_text_english if language == 'english' else mit_license_text_german
with open(mit_license_path, 'w') as f:
f.write(mit_license_text.strip())
def upload_to_gitea(repo_url, token, local_path, repo_name):
headers = {
'Authorization': f'token {token}',
'Content-Type': 'application/json',
}
if not repository_exists(repo_url, token, repo_name):
print("Repository does not exist. Creating...")
if not create_repository(repo_url, token, repo_name):
print("Repository creation failed. Aborting upload.")
return
if not os.path.exists(os.path.join(local_path, '.git')):
subprocess.run(["git", "config", "--global", "user.email", "E-Mail Adresse"])
subprocess.run(["git", "config", "--global", "user.name", "Name"])
subprocess.run(["git", "init"], cwd=local_path)
subprocess.run(["git", "checkout", "-b", "main"], cwd=local_path)
subprocess.run(["git", "add", "."], cwd=local_path)
subprocess.run(["git", "commit", "-m", "Add MIT License"], cwd=local_path)
remote_exists = subprocess.run(["git", "remote", "get-url", "origin"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=local_path)
if remote_exists.returncode != 0:
subprocess.run(["git", "remote", "add", "origin", f"https://example.com/Name/{repo_name}.git"], cwd=local_path)
subprocess.run(["git", "push", "-u", "origin", "main"], cwd=local_path)
if __name__ == "__main__":
repo_url = 'Gitea URL'
token = 'token'
local_path = r'local Pfad'
repo_name = 'Name'
#add_mit_license(local_path, language='english') # MIT License in English
add_mit_license(local_path, language='german') # MIT License in German
upload_to_gitea(repo_url, token, local_path, repo_name)