converted source releases to git

This commit is contained in:
Trilarion
2018-06-28 10:39:14 +02:00
parent 37ff720f05
commit f7fd84817e
24 changed files with 829 additions and 56 deletions

View File

@ -1,7 +1,6 @@
{
"git": [
"http://git.artsoft.org/rocksndiamonds.git",
"http://git.net-core.org/tome/t-engine4.git",
"http://git.pond.sub.org/empserver",
"http://repo.or.cz/openal-soft.git",
"https://anongit.freedesktop.org/git/pkg-config.git",
@ -35,6 +34,7 @@
"https://git.code.sf.net/p/solar-empire/code",
"https://git.code.sf.net/p/space-war-2/git",
"https://git.code.sf.net/p/stars-nova/code",
"https://git.net-core.org/tome/t-engine4.git",
"https://git.octaforge.org/engine/octaforge.git",
"https://git.savannah.gnu.org/git/adonthell/adonthell-wastesedge.git",
"https://git.savannah.gnu.org/git/freedink.git",
@ -274,6 +274,7 @@
"https://github.com/tales/tales-client.git",
"https://github.com/tarnus/aatraders.git",
"https://github.com/tautvilas/epoh.git",
"https://github.com/themanaworld/tmwa.git",
"https://github.com/thousandparsec/tpclient-pywx.git",
"https://github.com/thousandparsec/tpserver-cpp.git",
"https://github.com/topherredden/freestars.git",
@ -306,19 +307,26 @@
"https://gitlab.com/Trilarion/civilwar.git",
"https://gitlab.com/Trilarion/coltoo.git",
"https://gitlab.com/Trilarion/conquests.git",
"https://gitlab.com/Trilarion/devana.git",
"https://gitlab.com/Trilarion/digitalalovestory.git",
"https://gitlab.com/Trilarion/dragon-history.git",
"https://gitlab.com/Trilarion/dragon-hunt.git",
"https://gitlab.com/Trilarion/duelcommander.git",
"https://gitlab.com/Trilarion/dungeoncrawl.git",
"https://gitlab.com/Trilarion/galaxyng.git",
"https://gitlab.com/Trilarion/gm-tools.git",
"https://gitlab.com/Trilarion/gwiz.git",
"https://gitlab.com/Trilarion/janag.git",
"https://gitlab.com/Trilarion/koboldsquest2.git",
"https://gitlab.com/Trilarion/kursk.git",
"https://gitlab.com/Trilarion/lincity.git",
"https://gitlab.com/Trilarion/machinations.git",
"https://gitlab.com/Trilarion/mercenarycommander.git",
"https://gitlab.com/Trilarion/metalmech.git",
"https://gitlab.com/Trilarion/murderpd.git",
"https://gitlab.com/Trilarion/openrpgmaker.git",
"https://gitlab.com/Trilarion/orient.git",
"https://gitlab.com/Trilarion/phaosrpg.git",
"https://gitlab.com/Trilarion/pizza-business.git",
"https://gitlab.com/Trilarion/planets.git",
"https://gitlab.com/Trilarion/promisance.git",
@ -326,16 +334,20 @@
"https://gitlab.com/Trilarion/rogueclone.git",
"https://gitlab.com/Trilarion/sentient-storage.git",
"https://gitlab.com/Trilarion/skrupel.git",
"https://gitlab.com/Trilarion/slaygame.git",
"https://gitlab.com/Trilarion/spicetrade.git",
"https://gitlab.com/Trilarion/tbots.git",
"https://gitlab.com/Trilarion/theclans.git",
"https://gitlab.com/Trilarion/tuxracer.git",
"https://gitlab.com/Trilarion/uwadv.git",
"https://gitlab.com/Trilarion/wargamer.git",
"https://gitlab.com/Trilarion/watomic.git",
"https://gitlab.com/Trilarion/worldofheroes.git",
"https://gitlab.com/Trilarion/xconq.git",
"https://gitlab.com/Trilarion/zangband.git",
"https://gitlab.com/evol/evol-all.git",
"https://gitlab.com/freedroid/freedroid-src.git",
"https://gitlab.com/manaplus/manaplus.git",
"https://gitlab.com/pingus/pingus.git",
"https://gitlab.com/solarus-games/zsdx.git",
"https://gitlab.com/xonotic/xonotic.git",
@ -380,6 +392,7 @@
"https://bitbucket.org/featheredmelody/lost-sky-project-public/src",
"https://bitbucket.org/genericcontainer/goblin-camp/src",
"https://bitbucket.org/giszmo/glob2",
"https://bitbucket.org/mstrobel/supremacy",
"https://bitbucket.org/rude/love",
"https://bitbucket.org/sumwars/sumwars-code/src"
],

View File

@ -167,6 +167,8 @@ def run(type, urls):
if __name__ == '__main__':
supported_types = ['git', 'hg', 'svn'] # currently no bzr client installed
folder_name = {
'git': git_folder_name,
'svn': svn_folder_name,
@ -196,8 +198,7 @@ if __name__ == '__main__':
archives = json.loads(text)
for type in archives:
# currently no bzr checkout (problems with the repos)
if type == 'bzr':
if type not in supported_types:
continue
urls = archives[type]
run(type, urls)

View File

@ -0,0 +1,502 @@
"""
Helps me with importing source revisions into Git
"""
import shutil
import os
import subprocess
import tarfile
import zipfile
import distutils.dir_util
import sys
import urllib.request
import tempfile
import datetime
def extract_sources(source_path, type, destination_path):
"""
Extracts a zip, tar, ... to a destination path.
"""
if type == '.tbz2':
tar = tarfile.open(source_path, 'r')
os.chdir(destination_path)
tar.extractall()
elif type == '.zip':
with zipfile.ZipFile(source_path, 'r') as zip:
zip.extractall(destination_path)
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 single_revision():
"""
"""
# remove temp path completely and create again
print('clear temp')
if os.path.isdir(temp_path):
shutil.rmtree(temp_path)
os.mkdir(temp_path)
# download archive
print('download archive from ftp')
with urllib.request.urlopen(ftp_link) as response:
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
shutil.copyfileobj(response, tmp_file)
# unpack source files and delete archive
print('extract {} to temp'.format(os.path.basename(ftp_link)))
extract_sources(tmp_file.name, os.path.splitext(ftp_link)[1], temp_path)
os.remove(tmp_file.name)
# we need to go up in temp_path until we find the first non-empty directory
nonempty_temp_path = temp_path
names = os.listdir(nonempty_temp_path)
while len(names) == 1:
nonempty_temp_path = os.path.join(nonempty_temp_path, names[0])
names = os.listdir(nonempty_temp_path)
print(' working in "{}" relative to temp'.format(os.path.relpath(nonempty_temp_path, temp_path)))
# if no original date is indicated, get it from the files (latest of last modified)
global original_date
if original_date is None:
latest_last_modified = 0
for dirpath, dirnames, filenames in os.walk(nonempty_temp_path):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
lastmodified = os.path.getmtime(filepath)
if lastmodified > latest_last_modified:
latest_last_modified = lastmodified
original_date = datetime.datetime.fromtimestamp(latest_last_modified).strftime('%Y-%m-%d')
print(' extracted original date from files: {}'.format(original_date))
# clear git path without deleting '.git'
print('clear 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)
# copy unpacked source files to git path
print('copy to git')
distutils.dir_util.copy_tree(nonempty_temp_path, git_path)
# 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 {} ({}) on {}'.format(version, ftp_link, original_date)
print(' message "{}"'.format(message))
# subprocess_run(['git', 'commit', '--message={}'.format(message), '--author={}'.format(author), '--date={}'.format(original_date), '--dry-run'])
subprocess_run(['git', 'commit', '--message={}'.format(message), '--author={}'.format(author), '--date={}'.format(original_date)])
if __name__ == "__main__":
git_path = r'..\crawl' # must be initialized with 'git init' before
temp_path = r'..\temp'
author = 'Linley Henzell et al 1997-2005 <www.dungeoncrawl.org>' # is used for all commits
# 1.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/1.1.x/src/dc110f-src.tbz2'
# version = '110f'
# original_date = '1997-10-04' # format yyyy-mm-dd, according to versions.txt in version 400b26
# single_revision()
# 2.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/2.7.x/src/dc270f-src.tbz2'
# version = '270f'
# original_date = '1998-09-22'
# single_revision()
# 3.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/2.7.x/src/dc272f-src.tbz2'
# version = '272f'
# original_date = '1998-10-02'
# single_revision()
# 4.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/2.8.x/src/dc280f-src.tbz2'
# version = '280f'
# original_date = '1998-10-18'
# single_revision()
# 5.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/2.8.x/src/dc281f-src.tbz2'
# version = '281f'
# original_date = '1998-10-20'
# single_revision()
# 6.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/2.8.x/src/dc282f-src.tbz2'
# version = '282f'
# original_date = '1998-10-24'
# single_revision()
# 7.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/3.0.x/src/dc301f-src.tbz2'
# version = '301f'
# original_date = '1999-01-01'
# single_revision()
# 8.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/3.0.x/src/dc302f-src.tbz2'
# version = '302f'
# original_date = '1999-01-04'
# single_revision()
# 9.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/3.2.x/src/dc320f-src.tbz2'
# version = '320f'
# original_date = '1999-02-09'
# single_revision()
# 10.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/final/3.3.x/src/dc330f-src.tbz2'
# version = '330f'
# original_date = '1999-03-30'
# single_revision()
# 11.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/3.3.x/src/cr331beta01-src.zip'
# version = '331beta01'
# original_date = '1999-04-09' # "Date last modified" of every file inside and of that the latest
# single_revision()
# 12.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/3.3.x/src/cr331beta02-src.zip'
# version = '331beta02'
# original_date = '1999-06-18'
# single_revision()
# 13.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/3.3.x/src/cr331beta03-src.zip'
# version = '331beta03'
# original_date = '1999-06-22'
# single_revision()
# 14.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/3.3.x/src/cr331beta04-src.zip'
# version = '331beta04'
# original_date = '1999-08-08'
# single_revision()
# 15.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/3.3.x/src/cr331beta05-src.zip'
# version = '331beta05'
# original_date = '1999-08-27'
# single_revision()
# 16.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/3.3.x/src/cr331beta06-src.zip'
# version = '331beta06'
# original_date = '1999-09-12'
# single_revision()
# 17.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/3.3.x/src/cr331beta07-src.zip'
# version = '331beta07'
# original_date = '1999-09-24'
# single_revision()
# 18.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/3.3.x/src/cr331beta08-src.zip'
# version = '331beta08'
# original_date = '1999-09-28'
# single_revision()
# 19.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/3.3.x/src/cr331beta09-src.zip'
# version = '331beta09'
# original_date = '1999-10-02'
# single_revision()
# 20.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr1999oct12src.zip'
# version = 'cr1999oct12'
# original_date = '1999-10-12'
# single_revision()
# 21.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr1999oct15src.zip'
# version = 'cr1999oct15'
# original_date = '1999-10-15'
# single_revision()
# 22.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr1999nov18src.zip'
# version = 'cr1999nov18'
# original_date = '1999-11-18'
# single_revision()
# 23.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr1999nov23src.zip'
# version = 'cr1999nov23'
# original_date = '1999-11-23'
# single_revision()
# 24.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr1999dec27src.zip'
# version = 'cr1999dec27'
# original_date = '1999-12-27'
# single_revision()
# 25.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr1999dec30src.zip'
# version = 'cr1999dec30'
# original_date = '1999-12-30'
# single_revision()
# 26.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr1999dec31src.zip'
# version = 'cr1999dec31'
# original_date = '1999-12-31'
# single_revision()
# 27.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000jan10src.zip'
# version = 'cr2000jan10'
# original_date = '2000-01-10'
# single_revision()
# 28.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000feb23src.zip'
# version = 'cr2000feb23'
# original_date = '2000-02-23'
# single_revision()
# 29.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000mar06src.zip'
# version = 'cr2000mar06'
# original_date = '2000-03-06'
# single_revision()
# 30.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000jun19src.zip'
# version = 'cr2000jun19src'
# original_date = '2000-06-19'
# single_revision()
# 31.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000jun20src.zip'
# version = 'cr2000jun20'
# original_date = '2000-06-20'
# single_revision()
# 32.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000jun22src.zip'
# version = 'cr2000jun22'
# original_date = '2000-06-22'
# single_revision()
# 33.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000jul22src.zip'
# version = 'cr2000jul22'
# original_date = '2000-07-22'
# single_revision()
# 34.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000aug01src.zip'
# version = 'cr2000aug01'
# original_date = '2000-08-01'
# single_revision()
# 35.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000aug13src.zip'
# version = 'cr2000aug13'
# original_date = '2000-08-13'
# single_revision()
# 36.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/orphan/src/cr2000oct30src.zip'
# version = 'cr2000oct30'
# original_date = '2000-10-30'
# single_revision()
# 37.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta01-src.tbz2'
# version = '400beta01'
# original_date = None # 2000-12-20
# single_revision()
# 38.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta02-src.tbz2'
# version = '400beta02'
# original_date = None # 2000-12-22
# single_revision()
# 39.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta03-src.tbz2'
# version = '400beta03'
# original_date = None # 2000-12-29
# single_revision()
# 40.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta04-src.tbz2'
# version = '400beta04'
# original_date = None # 2001-01-11
# single_revision()
# 41.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta06-src.tbz2'
# version = '400beta06'
# original_date = None # 2001-01-23
# single_revision()
# 42.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta07-src.tbz2'
# version = '400beta07'
# original_date = None # 2001-01-29
# single_revision()
# 43.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta08-src.tbz2'
# version = 'cr400beta08'
# original_date = None # 2001-02-20
# single_revision()
# 44.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta09-src.tbz2'
# version = 'cr400beta09'
# original_date = None # 2001-03-06
# single_revision()
# 45.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta10-src.tbz2'
# version = 'cr400beta10'
# original_date = None # 2001-03-13
# single_revision()
# 46.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta10b-src.tbz2'
# version = 'cr400beta10b'
# original_date = None # 2001-03-14
# single_revision()
# 47.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta10c-src.tbz2'
# version = 'cr400beta10c'
# original_date = None # 2001-03-15
# single_revision()
# 48.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta10d-src.tbz2'
# version = '400beta10d'
# original_date = None # 2001-03-18
# single_revision()
# 49.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta11-src.tbz2'
# version = '400beta11'
# original_date = None # 2001-03-21
# single_revision()
# 50.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta12-src.tbz2'
# version = '400beta12'
# original_date = None # 2001-04-02
# single_revision()
# 51.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta13-src.tbz2'
# version = '400beta13'
# original_date = None # 2001-04-09
# single_revision()
# 52.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta14-src.tbz2'
# version = '400beta14'
# original_date = None # 2001-04-20
# single_revision()
# 53.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta15-src.tbz2'
# version = '400beta15'
# original_date = None # 2001-04-25
# single_revision()
# 54.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta16-src.tbz2'
# version = '400beta16'
# original_date = None # 2001-05-11
# single_revision()
# 55.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta17-src.tbz2'
# version = '400beta17'
# original_date = None # 2001-06-01
# single_revision()
# 56.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta18-src.tbz2'
# version = '400beta18'
# original_date = None # 2001-08-04
# single_revision()
# 57.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta19-src.tbz2'
# version = '400beta19'
# original_date = None # 2001-08-10
# single_revision()
# 58.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta20-src.tbz2'
# version = '400beta20'
# original_date = None # 2001-11-05
# single_revision()
# 59.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/cr400beta22-src.tbz2'
# version = '400beta22'
# original_date = None # 2001-12-21
# single_revision()
# 60.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/dc400b23-src.tbz2'
# version = '400b23'
# original_date = None # 2002-03-16
# single_revision()
# 61.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/dc400b24-src.tbz2'
# version = '400b24'
# original_date = '2002-06-03' # taken again from ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/
# single_revision()
# 62.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/dc400b25-src.tbz2'
# version = '400b25'
# original_date = '2003-03-06'
# single_revision()
# 63.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/dc400a26-src.tbz2'
# version = '400a26'
# original_date = '2003-03-17'
# single_revision()
# 64.
# ftp_link = 'ftp://ftp.dungeoncrawl.org/dev/4.0.x/src/dc400b26-src.tbz2'
# version = '400b26'
# original_date = '2003-03-24'
# single_revision()

49
tools/phaos.json Normal file
View File

@ -0,0 +1,49 @@
["https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.82/phaos-0.9.82-UPDATED-6.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.82/phaos-0.9.82-UPDATED-5.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.82/phaos-0.9.82-UPDATED-4.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.82/phaos-0.9.82-UPDATED-3.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.82/phaos-0.9.82-UPDATED-2.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.82/phaos-0.9.82-UPDATED.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.82/phaos-0.9.82.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.81/phaos-0.9.81.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.8/phaos-0.9.8.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.7/phaos-0.9.7.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9.6/phaos-0.9.6.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9/phaos-0.9.4.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9/phaos-0.9.3.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.9/phaos-0.9.2.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/Phaos%20Online%20RPG%20%28Source%20Code%29/Version%200.89/phaos-0.89.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.9.5.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.9.1.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.9.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.88.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.88-rc3.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.88-rc2.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.88-rc1.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.87-1.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.87.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.86.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.86-TEST-3.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.86-TEST-2.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.86-TEST-1.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.85.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.85-TEST-3.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.85-TEST-2.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.85-TEST-1.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.84.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.84-TEST2.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.84-TEST1.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.82.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.82-TEST3.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.82-TEST2.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.82-TEST1.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.8.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.77.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.76.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos-0.74.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/phaos0.72.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/Pv0.72.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/Pv0.7develnew.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/Pv0.7.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/Pv0.61.zip/download",
"https://sourceforge.net/projects/phaosrpg/files/OldFiles/Pv0.6.zip/download"]

View File

@ -0,0 +1,204 @@
"""
Downloads source releases from Sourceforge and puts them into a git repository
"""
import os
import shutil
import urllib.request
import json
import time
import zipfile
import subprocess
import datetime
import distutils.dir_util
import sys
def determine_version(name):
# to lower case
name = name.lower()
# cut leading terms
terms = ['phaos-', 'phaos', 'pv']
for t in terms:
if name.startswith(t):
name = name[len(t):]
# cut trailing '.zip'
t = '.zip'
if name.endswith(t):
name = name[:-len(t)]
return name
def determine_last_modified_date(folder):
latest_last_modified = 0
for dirpath, dirnames, filenames in os.walk(folder):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
lastmodified = os.path.getmtime(filepath)
if lastmodified > latest_last_modified:
latest_last_modified = lastmodified
return latest_last_modified
def unzip_keep_last_modified(archive, destination):
"""
Assuming that destination is a directory and already existing.
"""
with zipfile.ZipFile(archive, 'r') as zip:
# zip.extractall(destination)
for zip_entry in zip.infolist():
name, date_time = zip_entry.filename, zip_entry.date_time
date_time = time.mktime(date_time + (0, 0, -1))
zip.extract(zip_entry, destination)
os.utime(os.path.join(destination, name), (date_time, date_time))
def strip_wrapping(folder):
names = os.listdir(folder)
while len(names) == 1:
folder = os.path.join(folder, names[0])
names = os.listdir(folder)
return folder
def copy_tree(source, destination):
# this gave an FileNotFoundError: [Errno 2] No such file or directory: '' on Windows
# distutils.dir_util.copy_tree(archive_path, git_path)
for dirpath, dirnames, filenames in os.walk(source):
# first create all the directory on destination
directories_to_be_created = [os.path.join(destination, os.path.relpath(os.path.join(dirpath, x), source)) for x in dirnames]
for directory in directories_to_be_created:
os.makedirs(directory, exist_ok=True)
# second copy all the files
filepaths_source = [os.path.join(dirpath, x) for x in filenames]
filepaths_destination = [os.path.join(destination, os.path.relpath(x, source)) for x in filepaths_source]
for src, dst in zip(filepaths_source, filepaths_destination):
shutil.copyfile(src, dst)
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')))
if __name__ == '__main__':
# https://sourceforge.net/projects/phaosrpg/files/OldFiles/Pv0.7devel.zip/download is a corrupt zip
# base path is the directory containing this file
base_path = os.path.abspath(os.path.dirname(__file__))
print('base path={}'.format(base_path))
# recreate archive path
archive_path = os.path.join(base_path, 'downloads')
if not os.path.exists(archive_path):
os.mkdir(archive_path)
# load source releases urls
with open(os.path.join(base_path, 'phaos.json'), 'r') as f:
urls = json.load(f)
print('will process {} urls'.format(len(urls)))
if len(urls) != len(set(urls)):
raise RuntimeError("urls list contains duplicates")
# determine file archives from urls
archives = [x.split('/')[-2] for x in urls]
if len(archives) != len(set(archives)):
raise RuntimeError("files with duplicate archives, cannot deal with that")
# determine version from file name
versions = [determine_version(x) for x in archives]
# for version in versions:
# print(version)
# extend archives to full paths
archives = [os.path.join(archive_path, x) for x in archives]
# download them
print('download source releases')
for url, destination in zip(urls, archives):
# only if not yet existing
if os.path.exists(destination):
continue
# download
print(' download {}'.format(os.path.basename(destination)))
with urllib.request.urlopen(url) as response:
with open(destination, 'wb') as f:
shutil.copyfileobj(response, f)
time.sleep(1) # we are nice
# unzip them
print('unzip downloaded archives')
unzipped_archives = [x[:-4] for x in archives] # folder is archive name without .zip
for archive, unzipped_archive in zip(archives, unzipped_archives):
print(' unzip {}'.format(os.path.basename(archive)))
# only if not yet existing
if os.path.exists(unzipped_archive):
continue
os.mkdir(unzipped_archive)
# unzip
unzip_keep_last_modified(archive, unzipped_archive)
# go up in unzipped archives until the very first non-empty folder
unzipped_archives = [strip_wrapping(x) for x in unzipped_archives]
# determine date
dates = [determine_last_modified_date(x) for x in unzipped_archives]
dates_strings = [datetime.datetime.fromtimestamp(x).strftime('%Y-%m-%d') for x in dates]
# if len(dates_strings) != len(set(dates_strings)):
# raise RuntimeError("Some on the same day, cannot cope with that")
# gather all important stuff in one list and sort by dates
db = list(zip(urls, unzipped_archives, versions, dates, dates_strings))
db.sort(key=lambda x:x[3])
print('proposed order')
for url, _, version, _, date in db:
print(' date={} version={}'.format(date, version))
# git init
git_path = os.path.join(base_path, 'phaosrpg')
if os.path.exists(git_path):
shutil.rmtree(git_path)
os.mkdir(git_path)
os.chdir(git_path)
subprocess_run(['git', 'init'])
# now process revision by revision
print('process revisions')
git_author = 'eproductions3 <eproductions3@user.sourceforge.net>'
for url, archive_path, version, _, date in db:
print(' process version={}'.format(version))
# clear git path without deleting .git
print(' clear 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)
# copy unpacked source files to git path
print('copy to git')
copy_tree(archive_path, git_path)
# 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 {} ({}) on {}'.format(version, url, date)
print(' message "{}"'.format(message))
subprocess_run(['git', 'commit', '--message={}'.format(message), '--author={}'.format(git_author), '--date={}'.format(date)])