Package: jutge_cli
IntroInstallationGlobal installation (root)Archlinux PKGBUILDInstallation using virtualenv (no root)UsageConfigurationBasic optionsProblem setsLogin credentialsAuthenticate to jutgelogin commandcookie commandcookie flagCommandsadd-test (add)archivecheckcookiedownload (down)loginnewshowtestimportupload (up)LicenseIntrojutge_cliis a python3 console application that aims to automate common
tasks when working withjutge.orgproblems. Those tasks
include:Creating new files named after problem title given the problem codeDisplaying statement and public test cases of a given problemCompiling and testing a program against public test casesUploading program solutions tojutge.orgCheckingjutge.orgresults for last submissions or for
a specific problem.Adding ant testing against custom test cases to a problemBatch uploading problems from a given problem setBatch creating new files of a given problem setExtract and rename problem solutions from ajutge.orgzip file export
to a specific folder.Installationjutge_cliis included inpypiand as such, it can be installed throughpip3.Global installation (root)To install python module run:sudopip3installjutge_cliThis should install all dependencies and create an executable namedjutgein/usr/bin/jutge.Archlinux PKGBUILDThere is also aPKGBUILDincluded in the repository for arch linux users.Installation using virtualenv (no root)You can install this program inside of a python3virtualenv:virtualenv-p/usr/bin/python3jutge_cli_venv&&cdjutge_cli_venvsourcebin/activatepip3installjutge_cliOnce the above commands complete successfully, thejutgewill be installed
inside thebinfolder of the virtualenv. It is recommended to link it to
the userbinfolder and add it to your$PATH.mkdir~/binln-sbin/jutge~/bin/jutgeRemember to add bin to your path by adding the following line to.bashrcor equivalent:exportPATH=$PATH:~/binUsageTo usejutge_clirun the commandjutgefollowed by the
subcommand you want to execute:jutge[SUBCOMMAND][SUBCOMMAND_OPTIONS]For the program to work you will have to either specify the code of the
problem you want to test (-cflag) or rename the program file so
that it begins with the code. The code must match the following regular
expression:[PGQX]\d{5}_(ca|en|es)(note that the code includes the
language although it is not mandatory).ConfigurationYou can configure default parameters through the YAML configuration file:~/.jutge_cli.yaml.Basic optionsThe following example lists all the basic options and
their default values:database:~/Documents/jutge/DBregex:'[PGQX]\d{5}_(ca|en|es)'diff-prog:diffdiff-flags:-yinp-suffix:inpcor-suffix:corfolder:~/Documents/jutge/DoneThose options can also be specified using the flags with the same name.Although you can change the regex it isnotrecommended to do so since bad
regex may break correct functionality.Problem setsYou can also add problem sets with theproblem_setsgroup. These will
make the commandsnew,archiveandupdateclassify problems into
folders:problem_sets:P1:[P19724,P34279,P37297,P37469,P42042,P51126,P51352,P61634,P66529,P67171,P70955,P82374,P89265,P92351,P98960,P99182,X54725,X59678,X64734,X89070]P2:[P27341,P28754,P29448,P32046,P34451,P35547,P37500,P55622,P59539,P59875,P60816,P64976,P65171,P74398,P79784,P85370,P97156,X30229,X32391,X80452]P3:[P13623,P19991,P29973,P32533,P61061,P79817,P80660,P87323,P96767,X01646,X08783,X26853,X29759,X59091,X84338,X98097]The above configuration file will save problemsP19724,P34279...into
folderP1, problemsP27341,P28754...intoP2and so on.Login credentialsYou can also provide login credentials in the configuration file inside
the grouplogin:login:email:myemail@mydomain.compassword:mypasswordYou can omit either email, password or both and the login command will
prompt the user for input when issued.Authenticate to jutgeTo upload problem solutions or to access private problems (the ones which code
starts withX) you must be logged in intojutge.org.
The preferred method to login is through thejutge logincommand although
there are 2 more methods involving cookies.login commandIssuing the commandjutge loginwill prompt the user for their email and
password and save the session cookie for next use. If email or
password are already provided inLogin credentialsit will not prompt the
user to input them. For more details on the command seelogincookie commandThe commandjutge cookieaccepts a cookie as a parameter and will
store it for next use. For more details on the command seecookiecookie flagYou can also explicitly provide a cookie to each subcommand call through the--cookieflag:jutge--cookieMY_COOKIEdownload-cX00000Global flagsMost of the flags depend on the subcommands, but there are some global
flags that effect all subcommands. Those are:--regexMY_REGEXregular expression used to extract codes from filenames--cookieMY_COOKIECookie used to connect tojutge.org--databaseFOLDERChange database location--no-downloadIf this flag is provided,jutge_cliwill not attempt
to connect to the internetCommandsadd-test (add)archivecheckcookiedownload (down)loginnewshowtestimportupload (up)add-test (add)This command adds a custom test case into the database. A test case consists
of two files, the input that will be feed to the program and the expected
output or solution. Those files can be provided through the flags-i(input) and-o(expected output) or if omitted the user will be prompted to
input them manually through stdin.The following example will add the contents of filesinpandcorto
the database as test cases for the problemP00001_ca# Add the contents of inp and cor to the database for problem P00001_ca:jutgeadd-test-iinp-ocorP00001_ca_prog.cpp# Prompt the user to enter the input and expected output and add them to
# the database for problem P00001_ca:jutgeadd-testP00001_ca_prog.cpparchiveMove problem file to the archive folder. This folder can be
changed through the-fflag. To overwrite files already in the folder
use the--overwriteflag.The default behaviour is to move the file to the folder, if you want to copy
it instead use the--copyflag.The following example will move the fileP00001_ca_prog.cppto the
folderAcceptedand overwrite if already in the folder.jutgearchive--folderAccepted/P00001_ca_prog.cpp--overwritecheckChecks submissions tojutge.organd displays them in the terminal. The program will return 0 if the last
submission’s verdict isACor100/100and 1 otherwise.This subcommand accepts 3 flags:--lastshow only the last submission--reverseorder the output so that the last submission is on top--codecheck if a given problem code is accepted, rejected or not done
yetcookieAdd cookie provided as first argument to a temporary directory so it is used
for next commands. If the first argument isdeletethe current cookie
will be deleted and if the argument isprintorshowit will
output the current saved cookie.The command will check that the provided cookie is valid before saving the
value, to skip this check use the flag--skip-check.download (down)This command will attempt to download the html page and zip file corresponding
to the given problem fromjutge.organd add them to the
database. Either a code flag (-c) or a program file (-p) must be
provided.Note that other commands that depend on the database files will
automatically try to download them if they don’t exist and therefore
this command is only useful when populating the database in advance.The following example will populate the local database for problemP00001_en:jutgedownloadP00001_enloginPrompt the user to input their credentials and login tojutge.org. If
credentials are already specified in the configuration file (Login
credentials) it will not prompt for them.The flags--emailand--passwordcan be used to specify the credentials
without prompting and to override the ones specified in the configuration file.newThis command must be followed by a code. It will fetch the problem title
from the code and create a new file whose name is the code followed by
the title. The--extensionor-eflag can be used to specify the
extension of the file (defaults tocpp).If flag--problem-setis provided, all programs in the specified problem
set will be created inside a folder named after the problem set.The following example will populate create a new python file namedP87523_ca_-_Hola-adéu.pyjutgenewP87523_ca--extensionpyshowThis command provides 3 sub commands to print information about the problem.
Those are:titleprint problem titlestatprint statementcasesprint test cases in databaseBy defaultstatwill parse the problem statement throughpypandocto
optimize the output for terminal if you prefer raw HTML orpypandoctakes
to much time to parse the output you can use the flag--html.The following example will print all cases in the database for the problemP87523_ca(if any).jutgeshowcasesP87523_catestThis is the most useful command in the tool set. It allows to test your
code against all the test cases found in the database and output side by
side differences usingdiff.The command takes a file that can be either an executable or source file or
script of a supported language executable file as parameter and tests it
against the test cases in the database folder. Note that if the program if a
source file that needs to be compiled,jutge_cliwill compile it to
a file named after the original name with extension.x.You can specify an other program to act asdiff(such ascolordiff) and
its flags (separated by commas) through--diff-progand--diff-flags.The following example will test the executableP87523_ca_prog.xagainst
the test cases for problem P87523_ca. The expected output and the output of
the program will be shown side by side usingcolordiff.jutgetestP87523_ca_prog.x--diff-progcolordiffimportThis command extracts all accepted submissions from ajutge.orgzip file,
renames them according to their title and adds them to the archive folder
that can be specified through the-fflag or in the main configuration
file. Note that the zip file must be the one downloaded from yourjutge.orgprofile.jutgeimportproblems.zipupload (up)This command uploads a file tojutge.orgto be
evaluated. Note that you must have a valid cookie previously saved byjutge cookie PHPSSIDor you can provide it through the--cookieflag. As of
now, the program cannot report if the upload was successful so you will have to
check your submissions page manually. The compiler to use will be determined by
the filename extension but you can specify another one through the--compilerflag.jutgeuploadP00001_ca_prog.cpp--compiler'G++'If the flag--problem-setthe command will upload all problems from the
specified set found in the current working directory or in the set folder in
the current working directory. (Keep in mind thatjutge.orglimits the
number of submissions to 20 per hour so it is discouraged to use this flag
with large problem sets)By default upload will test all problems against public test cases in the
database (not including custom ones). You can skip those checks with the flag--skip-testIf you want to check the submitted problem verdict directly after upload, use
the flag--checkwhich will wait for the judge verdict and output it.LicenseThis software is licensed under theGPL v3 license.