博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文件移动
阅读量:6923 次
发布时间:2019-06-27

本文共 3849 字,大约阅读时间需要 12 分钟。

#!/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 i
1: 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()

 

转载于:https://www.cnblogs.com/yuchunju/archive/2012/06/29/2570376.html

你可能感兴趣的文章
Fat-tree 胖树交换网络
查看>>
楼塔当天领袖acm心理(作为励志使用)
查看>>
Java知多少(98)Graphics类的绘图方法
查看>>
SQL Server 有关EXCEPT和INTERSECT使用
查看>>
unix域套接字UDP网络编程
查看>>
.NET破解之谷歌地图下载助手-睿智版
查看>>
在Hekaton里,正确选择哈希存储桶数
查看>>
[火狐REST] 火狐REST 模拟 HTTP get, post请求
查看>>
浅谈HTML5单页面架构(二)——backbone + requirejs + zepto + underscore
查看>>
从头学起android&lt;AutoCompleteTextView文章提示文本框.十九.&gt;
查看>>
“NET网络”进行中,多管齐下的人才力挫“”粗俗
查看>>
What is Observer and Observable and when we used these?
查看>>
恢复spark挂掉的节点
查看>>
Overload和Override的区别 C++ Java
查看>>
查看mysqll账号信息
查看>>
failed to load the jni shared library jvm
查看>>
中国误区,你还抓?
查看>>
没有敢死队问题--约瑟夫变形
查看>>
C#使用ServiceController控制windows服务
查看>>
BZOJ2933 : [Poi1999]地图
查看>>