Package: cpsm
CPSM - Competitive Programming Solutions ManagerOverviewInstallationUsageExamplesCustomizationcpsm_config.pyUninstallationContributingCreditsCPSM is a tool for managing solutions to programming problems, particularly
competitive programming problems. It allows one to easily create and save new
solution files from templates.CPSM assumes that, in a given directory, you have several directories holding
solutions to problems. Furthermore, within each directory, there should be asolvingdirectory holding problems that you are working on. Thus, the
structure should look something like this:.
├── cpsm_config.py             <-- configuration file
├── website-1
│   ├── solution1.cpp
│   ├── solution2.py
│   ├── ...
│   └── solving
│       ├── solving1.cpp
│       └── solving2.py
└── website-2
    ├── solution1.cpp
    ├── solution2.py
    ├── ...
    └── solving
        ├── solving1.cpp
        └── solving2.pyThen, when you decide to save a file, it moves from the solving directory to its
main directory.InstallationCPSM requires Python 3.6 or later (compatibility with earlier versions may be
coming soon, however). To install, run:pip install cpsmIn a directory where you want to create solutions, docpsm initThis will walk you through a few steps and eventually create acpsm_config.pyfile with your configuration. You can modify thiscpsm_config.pyfile as you
wish, as long as you retain at least the original variables, as they are needed
by cpsm.UsageUSAGE: cpsm MODE [ARGS...]
  cpsm init | Initialize a directory for CPSM
  cpsm n abbrev problem template | Create a new solution (or open existing)
  cpsm r abbrev problem filetype | Run a solution
  cpsm s abbrev problem filetype | Save an existing solution
  cpsm h | Display this help messageExamplesCreate a new solution for the HackerRank problemJourney to the Moonusing thecpptemplate, where the abbreviation for HackerRank ishrand the directory
for it is hackerrank. Note that the template need not be namedcpp; it just so
happens that the template name matches the file extension here.cpsm n hr "Journey to the Moon" cppThis creates a journey-to-the-moon.cpp and journey-to-the-moon.txt file in the
hackerrank/solving directory and opens up an editor where you can work on the
files.Note that if any of these files exist already, they will simply be
opened.While coding, you can run your solution with the input file by doing:cpsm r hr "Journey to the Moon" cppBehind the scenes, this usesg++to compile journey-to-the-moon.cpp to create
a journey-to-the-moon.out file in the hackerrank/solving directory and runs it
with journey-to-the-moon.txt as input.Once you are done, you can move the files to the main hackerrank directory (i.e.
"save" them) with the following command. If your configuration file allows it,
the files will also be added and committed to the git repo. A prompt will be
provided if these files already exist in the directory.cpsm s hr "Journey to the Moon" cppNote that you do not need quotes around your problem title if your problem title
has no spaces. For example, you can docpsm n uva 12345 cpp.Customizationcpsm_config.pyConfigurations for CPSM are handled in acpsm_config.pyfile, which is created
upon runningcpsm init. An example is shown below.You can change thecpsm_config.pyfile at any time, as long as you maintain at
least the original variables, since they are used in CPSM. Here are some common
ways you might modify the file:Adding a template- You can do this by adding an entry into thetemplatesvariable. You will need to provide the name of the template, thefiletypethat it is for, and thecodeused for it.Thecodeis aJinjatemplate. You can
add "template variables" into it by putting them in double curly braces,
e.g.{{ variable }}. Then, you can define these variables in themappingsvariable.Adding an abbreviation- Modify theabbreviationsvariable, providing
thename,dir, andcreate_input_filealong with the new abbreviation.Adding a new filetype for running- Modify therun_commandsvariable,
providing a list of commands to run for the filetype.# Configuration file for CPSM# Command to run for opening the files when starting a new solutioneditor="vim -p"# Should CPSM open the input file along with the code file? This is particularly# useful if your editor does not support opening multiple filesopen_input=True# When saving, should CPSM add and commit the files to git? You can choose to# do this for one, both, or none of the code and input filessave_code_to_git={{save_code_to_git}}save_input_to_git={{save_input_to_git}}# Abbreviations for directories and full names of websites/competitions/etc.# Abbreviations should be of the following form:#   "(abbrev)": {#       "name": "(full name of website/competition/etc)",#       "dir": "(name of directory)",#       # Whether or not to create input files for problems in this directory#       "create_input_file": True/False,#   },abbreviations={"hr":{"name":"HackerRank","dir":"hackerrank","create_input_file":True,},}# Mapping of strings that can be inserted into the templates below. Note that# the following keys are reserved for use by CPSM:#   "name" - the name of the website/competition/etc for the problem#   "problem_name" - the title of the problem# If you include these keys, they simply will not be used.mappings={"username":"anonymous","fullname":"Anonymous Sample",}# Mapping of template names. Each template should be of the following form:#   "(template name)": {#       "filetype": "(file extension to use with this template)",#       "code": "(code for the template)",#   },# Substitution in the code is done using Jinja's Template.render(), with the# mappings above. In short, you can represent variables from the mappings above# by putting them in double curly braces, e.g. {{ variable }}. Refer to the# Jinja docs at http://jinja.pocoo.org/docs/2.10/ for more info.templates={"cpp":{"filetype":"cpp","code":"""\// Author: {{username}} ({{fullname}})// Problem: ({{name}}) {{problem_name}}#include <bits/stdc++.h>#define GET(x) scanf("%d", &x)#define GED(x) scanf("%lf", &x)typedef long long ll;using namespace std;typedef pair<int, int> ii;int main() {return 0;}""",},"cpp-blank":{"filetype":"cpp","code":"""\// Author: {{username}} ({{fullname}})// Problem: ({{name}}) {{problem_name}}""",},"py":{"filetype":"py","code":"""\# Author: {{username}} ({{fullname}})# Problem: ({{name}}) {{problem_name}}import sysfrom collections import defaultdict""",},"py-blank":{"filetype":"py","code":"""\# Author: {{username}} ({{fullname}})# Problem: ({{name}}) {{problem_name}}""",},}# A mapping of filetypes to a list of commands that should be run during run# mode. Each command should be of the form:#   "(filetype)": {#       ["(command 1)", "(command 2)", ...],#   },# Each command is interpreted as a jinja template, and there is only one# variable, "problem_name", that is used during substitution. "problem_name"# consists of the filename of the problem, with directories prepended to it.run_commands={"cpp":["g++ {{ problem_name }}.cpp -o {{ problem_name }}.out","{{ problem_name }}.out < {{ problem_name }}.txt",],"py":["python {{ problem_name }}.py < {{ problem_name }}.txt",],}UninstallationShould you ever decide to uninstall cpsm :scream:, simply run:pip uninstall cpsmYou may also want to remove yourcpsm_config.pyfiles if you are truly done
with CPSM.ContributingSeeCONTRIBUTING.md.CreditsKevin Wang, for encouraging me to push this to
a full projectTianjiao Huang, for being a pre-pre-pre-beta tester and suggesting the use
of Jinja