Script new_job_id_in_py
[hide private]
[frames] | no frames]

Source Code for Script script-new_job_id_in_py

 1  # -*- python -*- 
 2  # 
 3  # Git Version: @git@ 
 4   
 5  #----------------------------------------------------------------------- 
 6  # XALT: A tool that tracks users jobs and environments on a cluster. 
 7  # Copyright (C) 2013-2014 University of Texas at Austin 
 8  # Copyright (C) 2013-2014 University of Tennessee 
 9  #  
10  # This library is free software; you can redistribute it and/or modify 
11  # it under the terms of the GNU Lesser General Public License as 
12  # published by the Free Software Foundation; either version 2.1 of  
13  # the License, or (at your option) any later version.  
14  # 
15  # This library is distributed in the hope that it will be useful, 
16  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
18  # Lesser  General Public License for more details.  
19  # 
20  # You should have received a copy of the GNU Lesser General Public 
21  # License along with this library; if not, write to the Free 
22  # Software Foundation, Inc., 59 Temple Place, Suite 330, 
23  # Boston, MA 02111-1307 USA 
24  #----------------------------------------------------------------------- 
25  from __future__ import print_function 
26  import os, sys, MySQLdb  
27  dirNm, execName = os.path.split(sys.argv[0]) 
28  sys.path.append(os.path.abspath(os.path.join(dirNm, "../libexec"))) 
29   
30  from XALTdb     import XALTdb 
31  import warnings 
32  warnings.filterwarnings("ignore", "Unknown table.*") 
33   
34   
35 -def main():
36 ConfigBaseNm = "xalt_db" 37 ConfigFn = ConfigBaseNm + ".conf" 38 39 if (not os.path.isfile(ConfigFn)): 40 dirNm,prg = os.path.split(sys.argv[0]) 41 fn = os.path.join(dirNm, ConfigFn) 42 if (os.path.isfile(fn)): 43 ConfigFn = fn 44 else: 45 ConfigFn = os.path.abspath(os.path.join(dirNm,"../sbin",ConfigFn)) 46 47 48 xalt = XALTdb(ConfigFn) 49 try: 50 conn = xalt.connect() 51 except MySQLdb.Error, e: 52 print("-1") 53 sys.exit(1) 54 55 56 57 try: 58 query = "USE "+xalt.db() 59 conn.query(query) 60 query = "SELECT job_id FROM xalt_job_id WHERE inc_id='1'" 61 conn.query(query) 62 result = conn.store_result() 63 if (result.num_rows() > 0): 64 row = result.fetch_row() 65 job_id = int(row[0][0]) + 1 66 query = "UPDATE xalt_job_id SET job_id='%d' WHERE inc_id='1'" % job_id 67 conn.query(query) 68 69 print(job_id) 70 71 72 73 74 75 except MySQLdb.Error, e: 76 print ("Error %d: %s" % (e.args[0], e.args[1])) 77 sys.exit (1)
78 79 if ( __name__ == '__main__'): main() 80