File: crontest

package info (click to toggle)
python-crontab 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 520 kB
  • sloc: python: 2,783; makefile: 8; sh: 6
file content (50 lines) | stat: -rwxr-xr-x 1,343 bytes parent folder | download
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
43
44
45
46
47
48
49
50

import os
import sys

def main():
    """Run this"""
    args = sys.argv[1:]
    loc = os.path.dirname(__file__)

    if '-h' in args:
        print('|'.join(sorted(args)))
        return
    elif '-e' in args:
        sys.stderr.write('|'.join(sorted(args)) + "\n")
        return
    elif '-ev' in args:
        print(os.environ.get('CR_VAR', 'FAILED') + '\n')
        return

    user = 'user'
    if '-u' in args:
        user = args[args.index('-u')+1]
    if user == 'john':
        sys.stderr.write("Program Error")
        sys.exit(2)

    if '-l' in args:
        if user == 'error':
            raise ValueError("Delibrate IO Error")
        if not os.path.exists(os.path.join(loc, 'spool', user)):
            sys.stderr.write("no crontab for %s\n" % user)
            sys.exit(1)
        fhl = open(os.path.join(loc, 'spool', user), 'r')
        print(fhl.read())
        return

    for filename in args:
        if filename[0] == '-' or filename == user:
            continue
        new_name = os.path.join(loc, 'spool', user)
        if not os.path.exists(filename):
            raise KeyError("Can't find file: {}".format(filename))
        with open(filename, 'r') as source:
            with open(new_name, 'w') as output:
                output.write(source.read())

if __name__ == '__main__':
    main()
    sys.exit(0)