some conversions of repositories to Git

This commit is contained in:
Trilarion
2019-08-07 13:36:53 +02:00
parent b5ee111162
commit 105e0bfb3c
24 changed files with 207 additions and 51 deletions

View File

@ -143,6 +143,7 @@
"https://github.com/TASVideos/desmume.git",
"https://github.com/TVTower/TVTower.git",
"https://github.com/TobiasBielefeld/Simple-Solitaire.git",
"https://github.com/Trilarion/D-Fend-Reloaded.git",
"https://github.com/Trilarion/mpango.git",
"https://github.com/Trilarion/spacetraderjava.git",
"https://github.com/Tuxemon/Tuxemon.git",
@ -433,6 +434,7 @@
"https://gitlab.com/osgames/murderpd.git",
"https://gitlab.com/osgames/nxtank.git",
"https://gitlab.com/osgames/openblox.git",
"https://gitlab.com/osgames/opencity.git",
"https://gitlab.com/osgames/openrpg.git",
"https://gitlab.com/osgames/openrpgmaker.git",
"https://gitlab.com/osgames/openyahtzee.git",
@ -449,8 +451,10 @@
"https://gitlab.com/osgames/rogueclone.git",
"https://gitlab.com/osgames/rpdungeon.git",
"https://gitlab.com/osgames/rpge.git",
"https://gitlab.com/osgames/scrabble3d.git",
"https://gitlab.com/osgames/sdl-asylum.git",
"https://gitlab.com/osgames/sdl-sopwith.git",
"https://gitlab.com/osgames/sengoku.git",
"https://gitlab.com/osgames/sge2d.git",
"https://gitlab.com/osgames/sharpkonquest.git",
"https://gitlab.com/osgames/skrupel.git",
@ -465,6 +469,7 @@
"https://gitlab.com/osgames/theclans.git",
"https://gitlab.com/osgames/torcs.git",
"https://gitlab.com/osgames/trophy.git",
"https://gitlab.com/osgames/tumiki.git",
"https://gitlab.com/osgames/tuxfootball.git",
"https://gitlab.com/osgames/tuxracer.git",
"https://gitlab.com/osgames/uaf.git",
@ -503,10 +508,8 @@
"https://svn.code.sf.net/p/freesynd/code/",
"https://svn.code.sf.net/p/fsc/code/",
"https://svn.code.sf.net/p/lgames/code/",
"https://svn.code.sf.net/p/opencity/code/",
"https://svn.code.sf.net/p/pio/code/",
"https://svn.code.sf.net/p/planeshift/code/",
"https://svn.code.sf.net/p/scrabble/code/",
"https://svn.code.sf.net/p/space-faring/code/",
"https://svn.code.sf.net/p/spacezero/code/",
"https://svn.code.sf.net/p/speed-dreams/code/",
@ -519,7 +522,7 @@
"http://hg.code.sf.net/p/grobots/trunk",
"http://hg.code.sf.net/p/openblox/openblox",
"http://hg.code.sf.net/p/phantasy/code",
"http://hg.code.sf.net/p/xpilotgame/xpilotgame",
"http://hg.code.sf.net/p/xpilotgame/www.xpilot.org (hg",
"http://hg.libsdl.org/SDL",
"https://bitbucket.org/Darthman/quad/src",
"https://bitbucket.org/allacrost/allacrost/src",

View File

@ -0,0 +1,150 @@
"""
Converts the source releases of D-Fend Reloaded to a Git.
"""
import sys
import os
import shutil
import zipfile
import datetime
import subprocess
import re
import time
def subprocess_run(cmd):
"""
"""
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode:
print("error {} in call {}".format(result.returncode, cmd))
print(result.stderr.decode('ascii'))
sys.exit(-1)
else:
print(' output: {}'.format(result.stdout.decode('ascii')))
def unzip(zip_file, destination_directory):
dirs = {}
with zipfile.ZipFile(zip_file, 'r') as zip:
for info in zip.infolist():
name, date_time = info.filename, info.date_time
name = os.path.join(destination_directory, name)
zip.extract(info, destination_directory)
# still need to adjust the dt o/w item will have the current dt
date_time = time.mktime(info.date_time + (0, 0, -1))
if os.path.isdir(name):
# changes to dir dt will have no effect right now since files are
# being created inside of it; hold the dt and apply it later
dirs[name] = date_time
else:
os.utime(name, (date_time, date_time))
# done creating files, now update dir dt
for name in dirs:
date_time = dirs[name]
os.utime(name, (date_time, date_time))
def single_release(zip):
"""
"""
# get version
matches = version_regex.findall(zip)
version = matches[0]
print(' version {}'.format(version))
ftp_link = 'https://sourceforge.net/projects/dfendreloaded/files/D-Fend%20Reloaded/D-Fend%20Reloaded%20{}/'.format(version)
# clear git path without deleting '.git'
for item in os.listdir(git_path):
# ignore '.git
if item == '.git':
continue
item = os.path.join(git_path, item)
if os.path.isdir(item):
shutil.rmtree(item)
else:
os.remove(item)
# unpack zip to git path
# with zipfile.ZipFile(os.path.join(source_releases_path, zip), 'r') as zipf:
# zipf.extractall(git_path)
unzip(os.path.join(source_releases_path, zip), git_path)
# get date from the files (latest of last modified)
latest_last_modified = 0
for dirpath, dirnames, filenames in os.walk(git_path):
if dirpath.startswith(os.path.join(git_path, '.git')):
# not in '.git'
continue
for filename in filenames:
filepath = os.path.join(dirpath, filename)
lastmodified = os.path.getmtime(filepath)
if lastmodified > latest_last_modified:
latest_last_modified = lastmodified
# print('{}, {}'.format(filepath, datetime.datetime.fromtimestamp(latest_last_modified).strftime('%Y-%m-%d')))
original_date = datetime.datetime.fromtimestamp(latest_last_modified).strftime('%Y-%m-%d')
print(' last modified: {}'.format(original_date))
# update the git index (add unstaged, remove deleted, ...)
print('git add')
os.chdir(git_path)
subprocess_run(['git', 'add', '--all'])
# perform the commit
print('git commit')
os.chdir(git_path)
message = 'version {} from {} ({})'.format(version, original_date, ftp_link)
print(' message "{}"'.format(message))
subprocess_run(['git', 'commit', '--message={}'.format(message), '--author={}'.format(author), '--date={}'.format(original_date)])
def recreate_directory(path):
"""
"""
if os.path.isdir(path):
shutil.rmtree(path)
for attempts in range(10):
try:
os.mkdir(path)
except PermissionError:
time.sleep(0.1)
continue
else:
break
else:
raise RuntimeError()
if __name__ == "__main__":
# general properties
author = 'alexanderherzog <alexanderherzog@users.sourceforge.net>'
version_regex = re.compile(r"Reloaded-(.*)-", re.MULTILINE)
# get paths
source_releases_path = sys.argv[1]
git_path = os.path.join(source_releases_path, 'git')
# recreate git path
recreate_directory(git_path)
os.chdir(git_path)
subprocess_run('git init')
# get all files in the source releases path and sort them
zips = os.listdir(source_releases_path)
zips = [file for file in zips if os.path.isfile(os.path.join(source_releases_path, file))]
print('found {} source releases'.format(len(zips)))
zips.sort()
# iterate over them and do revisions
for counter, zip in enumerate(zips):
print('{}/{}'.format(counter, len(zips)))
single_release(zip)

View File

@ -1,5 +1,5 @@
"""
Helps me with importing source revisions into Git
Helps me with importing source revisions into Git
"""
import shutil

View File

@ -7,7 +7,7 @@ TODO instead of svn export for every revision, checkout and then update to revis
"""
import json
import sys
import psutil
from utils.utils import *

View File

@ -6,7 +6,6 @@ import json
import datetime
from utils.utils import *
if __name__ == '__main__':
# https://sourceforge.net/projects/phaosrpg/files/OldFiles/Pv0.7devel.zip/download is a corrupt zip

View File

@ -1,6 +1,6 @@
"""
Checks a list of game names (comma separated in text file) if they are already included in the database.
Is fuzzy, i.e. accepts a certain similarity of names.
Checks a list of game names (comma separated in text file) if they are already included in the database.
Is fuzzy, i.e. accepts a certain similarity of names.
"""
import json

View File

@ -1,5 +1,5 @@
"""
Where no requirements.txt or setup.py or other information is given, get an idea of the external dependencies
Where no requirements.txt or setup.py or other information is given for a Python project, get an idea of the external dependencies
by parsing the Python files and looking for import statements.
"""