Skip to content

Commit 933e175

Browse files
author
jorges
committed
GCJ Command Line v1.0-beta4, released 2011-06-03
[Feature]: Source files specified in the configuration files and using the -a option in gcj_submit_solution.py can now be glob patterns. [Feature]: In the tools/ directory there is an update_hashbangs.py script to change the hashbang line of a bulk of python files using a single command. [Fix]: --base_dir option was not working in gcj_submit_solution.py. [Fix]: Default value for --base_dir was not following symlinks properly. [Fix]: User status script was crashing when the user is not logged in or did not participate in the contest. [Fix]: Configuration file reading was crashing when spaces were inserted before the opening brace. A fix was made to clean the configuration file before attempting to parse it.
1 parent 2aac83b commit 933e175

12 files changed

+212
-36
lines changed

CHANGES

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
-------------------------------------------------------------------------------
2+
GCJ Command Line v1.0-beta4, released 2011-06-03
3+
4+
[Feature]: Source files specified in the configuration files and using the -a
5+
option in gcj_submit_solution.py can now be glob patterns.
6+
7+
[Feature]: In the tools/ directory there is an update_hashbangs.py script to
8+
change the hashbang line of a bulk of python files using a single
9+
command.
10+
11+
[Fix]: --base_dir option was not working in gcj_submit_solution.py.
12+
13+
[Fix]: Default value for --base_dir was not following symlinks properly.
14+
15+
[Fix]: User status script was crashing when the user is not logged in or did
16+
not participate in the contest.
17+
18+
[Fix]: Configuration file reading was crashing when spaces were inserted before
19+
the opening brace. A fix was made to clean the configuration file before
20+
attempting to parse it.
21+
122
-------------------------------------------------------------------------------
223
GCJ Command Line v1.0-beta3, released 2011-05-12
324

README

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GCJ Commandline submit tool, v1.0-beta3
1+
GCJ Commandline submit tool, v1.0-beta4
22
Copyright 2010 Google Inc. All Rights Reserved.
33

44
Download and submit tool for the Google Code Jam
@@ -127,8 +127,8 @@ which will download the input file and store it in source/A-small-0.in. Now
127127
it is time to run your solution and generate the output file.
128128

129129
NOTE: This script downloads an input file for the specified problem and starts
130-
its timer without asking a confirmation. You should double-check the parameters
131-
before running it or you might start a timer for another problem.
130+
its timer without asking for confirmation. You should double-check the
131+
parameters before running it or you might start a timer for another problem.
132132

133133
NOTE: Downloading an input file twice in the same attempt will just redownload
134134
the same input file if its timer has *NOT* expired. Otherwise, it will download
@@ -155,9 +155,9 @@ to submit two extra files called library.cpp and template.txt you can execute:
155155
$ ./gcj_submit_solution.py -a library.cpp -a template.txt A small 0
156156

157157
which will submit the file source/A-small-0.out as the answer and
158-
source/A-small-0.cpp and library.cpp as the source files. If you add a
159-
directory using the -a option, the program will compress it into a zip file
160-
before submitting it.
158+
source/A-small-0.cpp, library.cpp and template.txt as the source files. If you
159+
add a directory using the -a option, the program will compress it into a zip
160+
file before submitting it.
161161

162162
After submitting the file, the Code Jam server will answer with a message
163163
string. The most important values are:
@@ -176,7 +176,7 @@ string. The most important values are:
176176

177177
During the contest you can check your status by using the gcj_get_status.py
178178
script, which will show you your current rank, number of points, time at which
179-
input has been solved, number of wrong attempts per input and remaining time for
179+
each input was solved, number of wrong attempts per input and remaining time for
180180
current attempts.
181181

182182
To run this script you should execute:

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python2
1+
#!/usr/bin/env python2
22
# -*- coding: utf-8 -*-
33
#
44
# Copyright 2011 Google Inc.

gcj_clear_contest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def main():
4747
parser.add_option('--base_dir', action='store', dest='base_dir',
4848
help=('Base directory used to parametrize configuration '
4949
'file paths'))
50-
parser.set_defaults(base_dir=os.path.dirname(__file__))
50+
parser.set_defaults(base_dir=os.path.dirname(os.path.realpath(__file__)))
5151
options, args = parser.parse_args()
5252

5353
# Store the script location in a runtime constant, so it can be used by

gcj_download_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def main():
6767
help=('Base directory used to parametrize configuration '
6868
'file paths'))
6969
parser.set_defaults(renew_cookie=False, force=False,
70-
base_dir=os.path.dirname(__file__))
70+
base_dir=os.path.dirname(os.path.realpath(__file__)))
7171
options, args = parser.parse_args()
7272

7373
# Store the script location in a runtime constant, so it can be used by

gcj_get_status.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def main():
9494
parser.add_option('--base_dir', action='store', dest='base_dir',
9595
help=('Base directory used to parametrize configuration '
9696
'file paths'))
97-
parser.set_defaults(renew_cookie=False, base_dir=os.path.dirname(__file__))
97+
parser.set_defaults(renew_cookie=False,
98+
base_dir=os.path.dirname(os.path.realpath(__file__)))
9899
options, args = parser.parse_args()
99100

100101
# Store the script location in a runtime constant, so it can be used by

gcj_init_contest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def main():
4646
parser.add_option('--base_dir', action='store', dest='base_dir',
4747
help=('Base directory used to parametrize configuration '
4848
'file paths'))
49-
parser.set_defaults(base_dir=os.path.dirname(__file__))
49+
parser.set_defaults(base_dir=os.path.dirname(os.path.realpath(__file__)))
5050
options, args = parser.parse_args()
5151

5252
# Store the script location in a runtime constant, so it can be used by

gcj_renew_login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def main():
4646
parser.add_option('--base_dir', action='store', dest='base_dir',
4747
help=('Base directory used to parametrize configuration '
4848
'file paths'))
49-
parser.set_defaults(base_dir=os.path.dirname(__file__))
49+
parser.set_defaults(base_dir=os.path.dirname(os.path.realpath(__file__)))
5050
options, args = parser.parse_args()
5151

5252
# Store the script location in a runtime constant, so it can be used by

gcj_submit_solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def main():
9393
parser.set_defaults(renew_login=False, force=False, gzip_content=True,
9494
zip_sources=False, ignore_zip=False,
9595
ignore_def_source=False,
96-
base_dir=os.path.dirname(__file__))
96+
base_dir=os.path.dirname(os.path.realpath(__file__)))
9797
options, args = parser.parse_args()
9898

9999
# Store the script location in a runtime constant, so it can be used by

lib/output_submitter.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020

2121

22+
import glob
2223
import httplib
2324
import json
2425
import os
@@ -51,14 +52,16 @@ def __init__(self, host, cookie, middleware_token, contest_id, problem_id):
5152
self.contest_id = contest_id
5253
self.problem_id = problem_id
5354

54-
def _PrepareSourceFiles(self, source_names):
55+
def _PrepareSourceFiles(self, source_patterns):
5556
"""Zip all source directories into files and return them.
5657
5758
The returned list will contain (filename, file_data) tuples, where file_data
5859
will be None for files that have not been read yet.
5960
6061
Args:
61-
source_names: List with all the files to include with the solution.
62+
source_patterns: List with all the file patterns to include with the
63+
solution. These file patterns will be expanded using python's glob
64+
module.
6265
6366
Returns:
6467
A (source_files, ignored_zips) tuple, where source_files is a list of
@@ -70,23 +73,25 @@ def _PrepareSourceFiles(self, source_names):
7073
source_files = []
7174
ignored_zips = set()
7275

73-
# Process each source specified by the user.
74-
for source in source_names:
75-
# Check if the source is a directory or a file.
76-
if os.path.isdir(source):
77-
# Create a zip file in memory for the directory, add it to the source
78-
# files and update the ignored_zips set.
79-
sys.stdout.write('Compressing directory "{0}"...\n'.format(source))
80-
zipped_contents, newly_ignored_zips = (
81-
zip_utils.MakeZipFileInMemory([source], ignore_exts=['.zip']))
82-
ignored_zips.update(newly_ignored_zips)
83-
flat_source_name = source.replace('\\', '_').replace('/', '_')
84-
zip_filename = '{1}_{0}.zip'.format(random.randrange(0, 2**31 - 1),
85-
flat_source_name)
86-
source_files.append((zip_filename, zipped_contents))
87-
else:
88-
# Add files directly to the prepared sources.
89-
source_files.append((source, None))
76+
# Process each source pattern specified by the user, expanding them using
77+
# the python's glob module.
78+
for source_pattern in source_patterns:
79+
for source in glob.iglob(source_pattern):
80+
# Check if the source is a directory or a file.
81+
if os.path.isdir(source):
82+
# Create a zip file in memory for the directory, add it to the source
83+
# files and update the ignored_zips set.
84+
sys.stdout.write('Compressing directory "{0}"...\n'.format(source))
85+
zipped_contents, newly_ignored_zips = (
86+
zip_utils.MakeZipFileInMemory([source], ignore_exts=['.zip']))
87+
ignored_zips.update(newly_ignored_zips)
88+
flat_source_name = source.replace('\\', '_').replace('/', '_')
89+
zip_filename = '{1}_{0}.zip'.format(random.randrange(0, 2**31 - 1),
90+
flat_source_name)
91+
source_files.append((zip_filename, zipped_contents))
92+
else:
93+
# Add files directly to the prepared sources.
94+
source_files.append((source, None))
9095

9196
# Return all generated sets.
9297
return source_files, ignored_zips
@@ -123,15 +128,16 @@ def _ParseResult(self, response_data, input_public):
123128
'cannot submit solution. Check that the host, '
124129
'user and contest id are valid: {0}.\n'.format(e))
125130

126-
def Submit(self, input_id, output_name, source_names, input_public,
131+
def Submit(self, input_id, output_name, source_patterns, input_public,
127132
gzip_body=True, zip_sources=False, add_ignored_zips=False):
128133
"""Submit the specified output and sources file to the problem.
129134
130135
Args:
131136
input_id: Identifier of the output to submit ('0' for the small output,
132137
'1' for the large output).
133138
output_name: Name of the file with the output data.
134-
source_names: Names of the source files to be included with the output.
139+
source_patterns: Name patterns of the source files to be included with the
140+
output. These patterns will be expanded using Python's glob module.
135141
input_public: Boolean indicating whether the answer is public or not.
136142
gzip_body: Boolean indicating whether the body has to be gzipped or not.
137143
zip_sources: Boolean indicating whether all sources should be put inside a
@@ -150,7 +156,7 @@ def Submit(self, input_id, output_name, source_names, input_public,
150156
# Prepare the source files (zipping all directories). After this,
151157
# source_files will only contain text files and zip files specified directly
152158
# or by compressing a directory.
153-
source_files, ignored_zips = self._PrepareSourceFiles(set(source_names))
159+
source_files, ignored_zips = self._PrepareSourceFiles(set(source_patterns))
154160

155161
# Check if the user requested to zip source files.
156162
if zip_sources:

0 commit comments

Comments
 (0)