File: jobid.py

package info (click to toggle)
python-bumps 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,200 kB
  • sloc: python: 24,517; xml: 493; ansic: 373; makefile: 211; javascript: 99; sh: 94
file content (27 lines) | stat: -rw-r--r-- 601 bytes parent folder | download | duplicates (2)
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
import os

# from park import config
JOBID_PATH = os.path.expanduser("~/.jobqueue.job")

FID = None
CURRENT = None


def get_jobid():
    global FID, CURRENT
    if FID is None:
        path = JOBID_PATH
        if not os.path.exists(path):
            dir = os.path.dirname(path)
            if not os.path.exists(dir):
                os.makedirs(dir)
            FID = open(path, "w+")
            CURRENT = 0
        else:
            FID = open(path, "r+")
            CURRENT = int(FID.read())
    CURRENT += 1
    FID.seek(0)
    FID.write(str(CURRENT))
    FID.flush()
    return str(CURRENT)