-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy patharchive.py
122 lines (100 loc) · 5 KB
/
archive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Creates an archive of a BOSS release, putting it in the current folder.
# Files and folders that need to go in (relative to repository root):
#
# bin/Release-32/BOSS.exe
# bin/Release-32/BOSS GUI.exe
# data/resources/l10n/es/LC_MESSAGES/boss.mo
# data/resources/l10n/es/LC_MESSAGES/wxstd.mo
# data/resources/l10n/ru/LC_MESSAGES/boss.mo
# data/resources/l10n/ru/LC_MESSAGES/wxstd.mo
# data/resources/l10n/zh/LC_MESSAGES/boss.mo
# data/resources/l10n/zh/LC_MESSAGES/wxstd.mo
# data/resources/script.js
# data/resources/style.css
# data/BOSS.ini
# data/Docs
# BOSS
#
# A plugin load order optimiser for games that use the esp/esm plugin system.
#
# Copyright (C) 2009-2014 WrinklyNinja
#
# This file is part of BOSS.
#
# BOSS is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# BOSS is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BOSS. If not, see
# <http://www.gnu.org/licenses/>.
import sys
import os
import shutil
import zipfile
temp_path = u'archive.tmp'
archive_name = u'BOSS Archive.zip'
def onerror(func, path, exc_info):
"""
Error handler for ``shutil.rmtree``.
If the error is due to an access error (read only file)
it attempts to add write permission and then retries.
If the error is for another reason it re-raises the error.
Usage : ``shutil.rmtree(path, onerror=onerror)``
"""
import stat
if not os.access(path, os.W_OK):
# Is the error an access error ?
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise
# Set archive name if alternative is given.
if (len(sys.argv) > 1):
archive_name = sys.argv[1]
# First make sure that the temporary folder for the archive exists.
if not os.path.exists(temp_path):
os.makedirs(temp_path)
# Now copy everything into the temporary folder.
shutil.copy( os.path.join(u'bin', u'Release-32', u'BOSS.exe'), temp_path )
shutil.copy( os.path.join(u'bin', u'Release-32', u'BOSS GUI.exe'), temp_path )
for lang in ['es', 'ru', 'zh']:
os.makedirs(os.path.join(temp_path, 'resources', 'l10n', lang, 'LC_MESSAGES'))
shutil.copy( os.path.join('data', 'resources', 'l10n', lang, 'LC_MESSAGES', 'messages.mo'), os.path.join(temp_path, 'resources', 'l10n', lang, 'LC_MESSAGES') )
shutil.copy( os.path.join('data', 'resources', 'l10n', lang, 'LC_MESSAGES', 'wxstd.mo'), os.path.join(temp_path, 'resources', 'l10n', lang, 'LC_MESSAGES') )
shutil.copy( os.path.join('data', 'resources', 'script.js'), os.path.join(temp_path, 'resources') )
shutil.copy( os.path.join('data', 'resources', 'octokit.js'), os.path.join(temp_path, 'resources') )
shutil.copy( os.path.join('data', 'resources', 'promise-1.0.0.min.js'), os.path.join(temp_path, 'resources') )
shutil.copy( os.path.join('data', 'resources', 'style.css'), os.path.join(temp_path, 'resources') )
shutil.copy( os.path.join('data', 'BOSS.ini'), temp_path)
shutil.copytree( os.path.join('data', 'Docs'), os.path.join(temp_path, 'Docs') )
# Git repositories.
for game, boss_game in [('oblivion','Oblivion'), ('falloutnv','Fallout New Vegas'), ('skyrim','Skyrim'), ('fallout3','Fallout 3'), ('nehrim','Nehrim')]:
os.makedirs(os.path.join(temp_path, boss_game, '.git'))
shutil.copy(os.path.join('..', game, '.git', 'config'), os.path.join(temp_path, boss_game, '.git'))
shutil.copy(os.path.join('..', game, '.git', 'HEAD'), os.path.join(temp_path, boss_game, '.git'))
shutil.copy(os.path.join('..', game, '.git', 'index'), os.path.join(temp_path, boss_game, '.git'))
shutil.copy(os.path.join('..', game, '.git', 'packed-refs'), os.path.join(temp_path, boss_game, '.git'))
os.makedirs(os.path.join(temp_path, boss_game, '.git', 'refs', 'heads'))
shutil.copy(os.path.join('..', game, '.git', 'refs', 'heads', 'master'), os.path.join(temp_path, boss_game, '.git', 'refs', 'heads'))
os.makedirs(os.path.join(temp_path, boss_game, '.git', 'refs', 'remotes', 'origin'))
shutil.copy(os.path.join('..', game, '.git', 'refs', 'remotes', 'origin', 'HEAD'), os.path.join(temp_path, boss_game, '.git', 'refs', 'remotes', 'origin'))
shutil.copytree(os.path.join('..', game, '.git', 'objects'), os.path.join(temp_path, boss_game, '.git', 'objects'))
# Now compress the temporary folder. (Creating a zip because I can't get pylzma to work...)
os.chdir(temp_path)
zip = zipfile.ZipFile( os.path.join('..', archive_name), 'w', zipfile.ZIP_DEFLATED )
for root, dirs, files in os.walk('.'):
for file in files:
zip.write(os.path.join(root, file))
zip.close()
os.chdir('..')
# And finally, delete the temporary folder.
shutil.rmtree('archive.tmp', onerror=onerror)