File: jobid.py

package info (click to toggle)
python-bumps 0.7.11-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,264 kB
  • sloc: python: 22,226; ansic: 4,973; cpp: 4,849; xml: 493; makefile: 163; perl: 108; sh: 101
file content (25 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (3)
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
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)