Skip to content

Commit aeeb635

Browse files
committed
Move scripts I don't plan on maintaining to /example
1 parent b4a03e3 commit aeeb635

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed

sc2reader/scripts/sc2autosave.py renamed to examples/sc2autosave.py

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,17 @@
162162
import argparse
163163
import cPickle
164164
import os
165-
import gc
166165
import shutil
167166
import sys
168167
import time
169168

170169
import sc2reader
171170

171+
172172
def run(args):
173173
#Reset wipes the destination clean so we can start over.
174-
if args.reset: reset(args)
174+
if args.reset:
175+
reset(args)
175176

176177
#Set up validates the destination and source directories.
177178
#It also loads the previous state or creates one as necessary.
@@ -186,12 +187,12 @@ def run(args):
186187
try:
187188
#Read the file and expose useful aspects for renaming/filtering
188189
replay = sc2reader.load_replay(path, load_level=2)
189-
except KeyboardInterrupt as e:
190+
except KeyboardInterrupt:
190191
raise
191192
except:
192193
#Failure to parse
193194
file_name = os.path.basename(path)
194-
directory = make_directory(args,('parse_error',))
195+
directory = make_directory(args, ('parse_error',))
195196
new_path = os.path.join(directory, file_name)
196197
source_path = path[len(args.source):]
197198
args.log.write("Error parsing replay: {0}".format(source_path))
@@ -204,7 +205,8 @@ def run(args):
204205
aspects = generate_aspects(args, replay)
205206

206207
#Use the filter args to select files based on replay attributes
207-
if filter_out_replay(args, replay): continue
208+
if filter_out_replay(args, replay):
209+
continue
208210

209211
#Apply the aspects to the rename formatting.
210212
#'/' is a special character for creation of subdirectories.
@@ -232,14 +234,16 @@ def run(args):
232234
save_state(state, args)
233235

234236
#We only run once in batch mode!
235-
if args.mode == 'BATCH': break
237+
if args.mode == 'BATCH':
238+
break
236239

237240
#Since new replays come in fairly infrequently, reduce system load
238241
#by sleeping for an acceptable response time before the next scan.
239242
time.sleep(args.period)
240243

241244
args.log.write('Batch Completed')
242245

246+
243247
def filter_out_replay(args, replay):
244248
player_names = set([player.name for player in replay.players])
245249
filter_out_player = not set(args.filter_player) & player_names
@@ -249,10 +253,12 @@ def filter_out_replay(args, replay):
249253
else:
250254
return not filter_out_player
251255

256+
252257
# We need to create these compare functions at runtime because the ordering
253258
# hinges on the --favored PLAYER options passed in from the command line.
254259
def create_compare_funcs(args):
255260
favored_set = set(name.lower() for name in args.favored)
261+
256262
def player_compare(player1, player2):
257263
# Normalize the player names and generate our key metrics
258264
player1_name = player1.name.lower()
@@ -303,6 +309,7 @@ def team_compare(team1, team2):
303309

304310
return team_compare, player_compare
305311

312+
306313
def generate_aspects(args, replay):
307314
teams = sorted(replay.teams, args.team_compare)
308315
matchups, team_strings = list(), list()
@@ -314,14 +321,15 @@ def generate_aspects(args, replay):
314321
team_strings.append(string)
315322

316323
return sc2reader.utils.AttributeDict(
317-
result=teams[0].result,
318-
length=replay.length,
319-
map=replay.map,
320-
type=replay.type,
321-
date=replay.date.strftime(args.date_format),
322-
matchup='v'.join(matchups),
323-
teams=' vs '.join(team_strings)
324-
)
324+
result=teams[0].result,
325+
length=replay.length,
326+
map=replay.map,
327+
type=replay.type,
328+
date=replay.date.strftime(args.date_format),
329+
matchup='v'.join(matchups),
330+
teams=' vs '.join(team_strings)
331+
)
332+
325333

326334
def make_directory(args, path_parts):
327335
directory = args.dest
@@ -336,6 +344,7 @@ def make_directory(args, path_parts):
336344

337345
return directory
338346

347+
339348
def scan(args, state):
340349
args.log.write("SCANNING: {0}\n".format(args.source))
341350
files = sc2reader.utils.get_files(
@@ -347,8 +356,10 @@ def scan(args, state):
347356
followlinks=args.follow_links)
348357
return filter(lambda f: os.path.getctime(f) > state.last_sync, files)
349358

350-
def exit(msg,*args,**kwargs):
351-
sys.exit(msg.format(*args,**kwargs)+"\n\nScript Aborted.")
359+
360+
def exit(msg, *args, **kwargs):
361+
sys.exit(msg.format(*args, **kwargs)+"\n\nScript Aborted.")
362+
352363

353364
def reset(args):
354365
if not os.path.exists(args.dest):
@@ -366,9 +377,10 @@ def reset(args):
366377
else:
367378
sys.exit("Script Aborted")
368379

380+
369381
def setup(args):
370382
args.team_compare, args.player_compare = create_compare_funcs(args)
371-
args.action = sc2reader.utils.AttributeDict( type=args.action, run=shutil.copy if args.action=='COPY' else shutil.move)
383+
args.action = sc2reader.utils.AttributeDict(type=args.action, run=shutil.copy if args.action == 'COPY' else shutil.move)
372384
if not os.path.exists(args.source):
373385
msg = 'Source does not exist: {0}.\n\nScript Aborted.'
374386
sys.exit(msg.format(args.source))
@@ -384,7 +396,7 @@ def setup(args):
384396
elif not os.path.isdir(args.dest):
385397
sys.exit('Destination must be a directory.\n\nScript Aborted')
386398

387-
data_file = os.path.join(args.dest,'sc2autosave.dat')
399+
data_file = os.path.join(args.dest, 'sc2autosave.dat')
388400

389401
args.log.write('Loading state from file: {0}\n'.format(data_file))
390402
if os.path.isfile(data_file) and not args.reset:
@@ -393,11 +405,12 @@ def setup(args):
393405
else:
394406
return sc2reader.utils.AttributeDict(last_sync=0)
395407

408+
396409
def save_state(state, args):
397410
state.last_sync = time.time()
398-
data_file = os.path.join(args.dest,'sc2autosave.dat')
411+
data_file = os.path.join(args.dest, 'sc2autosave.dat')
399412
if not args.dryrun:
400-
with open(data_file,'w') as file:
413+
with open(data_file, 'w') as file:
401414
cPickle.dump(state, file)
402415
else:
403416
args.log.write('Writing state to file: {0}\n'.format(data_file))
@@ -418,11 +431,11 @@ def main():
418431

419432
general = parser.add_argument_group('General Options')
420433
general.add_argument('--mode', dest='mode',
421-
type=str, choices=['BATCH','CYCLE'], default='BATCH',
434+
type=str, choices=['BATCH', 'CYCLE'], default='BATCH',
422435
help='The operating mode for the organizer')
423436

424437
general.add_argument('--action', dest='action',
425-
choices=['COPY','MOVE'], default="COPY", type=str,
438+
choices=['COPY', 'MOVE'], default="COPY", type=str,
426439
help='Have the organizer move your files instead of copying')
427440
general.add_argument('--period',
428441
dest='period', type=int, default=0,
@@ -497,8 +510,8 @@ def main():
497510

498511
try:
499512
run(parser.parse_args())
500-
except KeyboardInterrupt as e:
513+
except KeyboardInterrupt:
501514
print "\n\nScript Interupted. Process Aborting"
502515

503516
if __name__ == '__main__':
504-
main()
517+
main()
File renamed without changes.

setup.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
license="MIT",
66
name="sc2reader",
77
version='0.5.1',
8-
keywords=["starcraft 2","sc2","replay","parser"],
8+
keywords=["starcraft 2", "sc2", "replay", "parser"],
99
description="Utility for parsing Starcraft II replay files",
1010
long_description=open("README.rst").read()+"\n\n"+open("CHANGELOG.rst").read(),
1111

@@ -31,22 +31,19 @@
3131
"Topic :: Software Development",
3232
"Topic :: Software Development :: Libraries",
3333
"Topic :: Utilities",
34-
],
34+
],
3535

3636
entry_points={
3737
'console_scripts': [
38-
'sc2autosave = sc2reader.scripts.sc2autosave:main',
3938
'sc2printer = sc2reader.scripts.sc2printer:main',
40-
'sc2store = sc2reader.scripts.sc2store:main',
4139
'sc2replayer = sc2reader.scripts.sc2replayer:main',
42-
'sc2boprinter = sc2reader.scripts.sc2boprinter:main',
4340
'sc2parse = sc2reader.scripts.sc2parse:main',
4441
'sc2attributes = sc2reader.scripts.sc2attributes:main',
4542
'sc2json = sc2reader.scripts.sc2json:main',
4643
]
4744
},
4845

49-
install_requires=['mpyq>=0.2.2','argparse','ordereddict'] if float(sys.version[:3]) < 2.7 else ['mpyq>=0.2.2'],
46+
install_requires=['mpyq>=0.2.2', 'argparse', 'ordereddict'] if float(sys.version[:3]) < 2.7 else ['mpyq>=0.2.2'],
5047
packages=setuptools.find_packages(),
5148
include_package_data=True,
5249
zip_safe=True

0 commit comments

Comments
 (0)