Skip to main content

Simple script launcher

Project description

Runscript package

It is not a rare case when the project has a few tasks to run periodically or at certain times e.g. deploying the project on the server or initial generation of data for new work place. Runscript package provides simple run utility that you can use to run your tasks. The run command is nothing more than launcher of the main() function of one of your scripts stored in predefined directory. Also run utility slightly simplifies the handling of command line arguments.

Real world example

Suppose you need to save some data from database into text file. For example, you have some web-site with user accounts and you want to dump the ID of each user account and also its email. Also you want to be able to choose the country of accounts to dump. Create "script/" directory in the root of your project and then create the file "script/dump.py" with content:

import pymongo

def setup_arg_parser(parser):
    parser.add_argument('-c', '--count')

def main(count, **kwargs):
    with open('export/user.csv', 'w') as out:
        for user in db.user.find({'country': country}):
            out.write('%s:%s\n' % (user['_id'], user['email'])) 

Few words about what is going here. The value of parser option that is passed to setup_arg_parser is the instance of ArgumentParser class. You can add any option you need or just do not specify setup_arg_parser in you script. If you define some custom options then their values will be passed in **kwargs arguments to your main function.

OK, now you can run the following command from the console:

$ run dump

That's all :) Of course this is not the rocket science, but I found that this simple script launcher saved me a lot of time.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runscript-0.3.1.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file runscript-0.3.1.tar.gz.

File metadata

  • Download URL: runscript-0.3.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for runscript-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e595cc01e325fdbcd29953d09c0111056ecfffc0ca972551d2cfad3cc5143f59
MD5 3e8459925e271bb14e18e3bbf2d15ee8
BLAKE2b-256 a7e3fb4d02f124a8057af14983d2546995a5ebfbc09fdf122b9834655a44621f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page