aboutsummaryrefslogtreecommitdiff
path: root/worker/worker1.py
blob: 8a315015ed34fab9aad5cde3457c7ab82fd2bcc4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
''' All this does is:
    1. Open an input file
    2. Read a list of integers (x)
    3. Add to the integers: x += 1
    4. Write list of integers to a new file
'''

import os
import argparse

PARSER = argparse.ArgumentParser()
PARSER.add_argument('--output-dir', '-o', default=os.path.abspath(os.curdir))
PARSER.add_argument('INFILE', action='store', nargs='*', help='Input file')
ARGS = PARSER.parse_args()

def do_work(ifile):
    ofile = os.path.join(ARGS.output_dir, os.path.basename(ifile))
    in_data = []
    
    print('Loading {} ({} bytes)'.format(ifile, os.path.getsize(ifile)))
    
    with open(ifile, 'r') as fp:
        for line in fp:
            line = line.rstrip()
            in_data.append(line)
    
    with open(ofile, 'w+') as fp:
        for value in in_data:
            fp.writelines('{}{}'.format(int(value)+1, os.linesep))
            
    

if __name__ == '__main__':
    if not ARGS.INFILE:
        print("No input file(s) received!")
        exit(1)
        
    for infile in ARGS.INFILE:
        do_work(os.path.abspath(infile))
    
    exit(0)