Skip to content

Instantly share code, notes, and snippets.

@shriphani
Created April 21, 2013 19:19
Show Gist options
  • Save shriphani/5430717 to your computer and use it in GitHub Desktop.
Save shriphani/5430717 to your computer and use it in GitHub Desktop.
Operate a heritrix instance hosted at the default address using the command line
'''
Heritrix control from the command line
All control can be done by using job directories on the command line
'''
import argparse
import os
def stop_job(job_dir):
job_name = os.path.basename(job_dir)
os.system('curl -v -d "action=terminate" -k -u admin:admin --anyauth --location https://localhost:8443/engine/job/%(job_name)s' % { 'job_name' : job_name })
def launch_job(job_dir):
job_name = os.path.basename(job_dir)
os.system('curl -v -d "action=launch" -k -u admin:admin --anyauth --location https://localhost:8443/engine/job/%(job_name)s' % { 'job_name' : job_name })
def add_job(job_dir):
os.system('curl -v -d "action=add&addpath=%(job_dir)s" -k -u admin:admin --anyauth --location https://localhost:8443/engine' % { 'job_dir' : job_dir })
def build_job(job_dir):
job_name = os.path.basename(job_dir)
os.system('curl -v -d "action=build" -k -u admin:admin --anyauth --location https://localhost:8443/engine/job/%(job_name)s' % { 'job_name' : job_name })
if __name__ == '__main__':
def parse_cmdline_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'current_job_dir',
metavar = 'current-job-dir',
nargs = '+',
help = ''
)
parser.add_argument(
'-l',
'--launch',
dest = 'launch',
action = 'store_true',
default = False,
help = 'Launch heritrix job'
)
parser.add_argument(
'-s',
'--stop',
dest = 'stop',
action = 'store_true',
default = False,
help = 'Stop heritrix job'
)
parser.add_argument(
'-a',
'--add',
dest = 'add',
action = 'store_true',
default = False,
help = 'Add job to heritrix'
)
parser.add_argument(
'-b',
'--build',
dest = 'build',
action = 'store_true',
default = False,
help = 'Build job'
)
return parser.parse_args()
parsed = parse_cmdline_args()
for job_dir in parsed.current_job_dir:
if parsed.stop:
stop_job(job_dir)
elif parsed.launch:
launch_job(job_dir)
elif parsed.stop:
stop_job(job_dir)
elif parsed.add:
add_job(job_dir)
elif parsed.build:
build_job(job_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment