#!/usr/bin/python#Filename :smelter_move.py# -*- coding:utf-8 -*-import cx_Oracleimport osimport datetimeimport os.pathimport shutilimport sysimport getopt,stringclass Filemove_module(object): def __init__(self,user_name,user_password,dns): self.user_name=user_name self.user_password=user_password self.dns=dns def conn_db(self): db=cx_Oracle.connect(self.user_name,self.user_password,self.dns) return db def c_process_id(self,pid): db=cx_Oracle.connect(self.user_name,self.user_password,self.dns) cursor=db.cursor() pro_pid=cursor.var(cx_Oracle.NUMBER) cursor.callproc("common.process_id",[pid,pro_pid]) return pro_pid.getvalue() db.close() def prhelp(self): print ''' Usage: smelter_move.py [options] Options: -h, --help show this help message and exit -i, --interid assign to interface id -d, --dayid assign to file date -n, --process assign to process id -s, --sourcedir assign to source directory -p, --targetdir assign to target directory Example: smelter_move.py -i 30 -d 20110502 -n 0 -s /tmp/test0604 -p /hadoop/pigtmp/sj0109/sj ''' def find_file(self,table_id,data_date,process_id,current_directory): db=self.conn_db() cursor=db.cursor() cursor.execute("select type_id from dm_type where type_code=\'FILE_MOVE\'") b=cursor.fetchall() #print b[0][0] tp_id = b[0][0] if len(data_date)==8: data_ymd=data_date data_h='000000' elif len(data_date)==14: data_ymd=data_date[0:8] data_h=data_date[8:14] cursor.execute('select t1.if_file_name,t1.file_type,t1.file_id from log_file t1 join dm_type t2 on t1.type_id=t2.type_id where t1.table_id=:tid and t1.data_date=:dt_dt and t1.current_directory=:crt and t2.type_code<>\'FILE_COPY\' and t2.type_code<>\'FILE_MOVE\' and t2.type_code<>\'FILE_DELETE\' and t1.status=\'S\'',tid=table_id,dt_dt=data_ymd,crt=current_directory ) a=cursor.fetchall() source_file=[] i=0 if len(a)>0: while i1: opts, args = getopt.getopt(sys.argv[1:], "i:d:n:s:p:h", ["interid=","dayid=","process=","sourcedir=","targetdir","help"]) for a,o in opts: if a in ('-i', '--interid'): INTERID=o #print o elif a in ('-d','--dayid'): #print o DAYID=o elif a in ('-n','--work'): PROCESS=o #print o elif a in ('-s', '--sourcedir'): SOURCEDIR=o #print o elif a in ('-p', '--targetdir'): TARGETDIR=o #print o elif a in ('-h', '--help'): self.prhelp() sys.exit() if len(DAYID)==8: date_ymd=DAYID date_h='000000' elif len(DAYID)==14: date_ymd=DAYID[0:8] date_h=DAYID[8:14] else: print 'Please input right day' self.prhelp() sys.exit() #print INTERID,DAYID,PROCESS,SOURCEDIR,TARGETDIR f_move=self.fun_move(INTERID,DAYID,PROCESS,SOURCEDIR,TARGETDIR) print f_move except Exception as e: return 'input parameter error!',eif __name__ == '__main__': job_set=Filemove_module('','','') job_set.main()