import sys,os,stat,getopt,tempfile,shutil,struct,subprocess
mtypes = [
'zip',
'rar',
'tar',
'gz'
]
if __name__ == '__main__':
opts,args=getopt.gnu_getopt(sys.argv[1:],"i:t:v:n:h:o:", ["input=", "name=", "type=", "help=", "version=", "outfile="])
itypes = []
for o,a in opts:
if o in ('-n', '--name'):
print 'name=%s' % (a)
elif o in ('-i', '--input'):
filename = os.path.abspath(a)
fstat = os.stat(filename)
# fd = open(filename, "a")
# fstat = os.fstat(fd.fileno())
print fstat
# ST_ATIME = 7
# ST_CTIME = 9
# ST_DEV = 2
# ST_GID = 5
# ST_INO = 1
# ST_MODE = 0
# ST_MTIME = 8
# ST_NLINK = 3
# ST_SIZE = 6
# ST_UID = 4
# S_IROTH = 4
# S_IRWXO = 7
# S_IWOTH = 2
# S_IXGRP = 8
# S_IXOTH = 1
print 'mode=%o' % fstat[stat.ST_MODE]
print 'inode number=%d' % fstat[stat.ST_INO]
print 'size=%d' % fstat[stat.ST_SIZE]
fd = open(filename, "a")
fd.write(struct.pack('i', fstat[stat.ST_SIZE])) # equal to linux kernel attr : __attribute__ ((packed)) help(struct)[luther.gliethttp])
fd.close()
elif o in ('-o', '--outfile'):
print 'outputfile abs path=%s' % os.path.abspath(a)
elif o in ('-t', '--type'):
type = a.lower()
if type in mtypes:
itypes.append(type)
else:
print 'not support type : %s' % (type)
elif o in ('-v', '--version'):
print 'version 1.0'
sys.stdout.flush()
sys.exit()
elif o in ('-h', '--help'):
print 'luther:gliethttp\njust for test'
sys.stdout.flush()
sys.exit()
else:
print 'Usage...'
print '########\n',sys.path,'\n########' print sys.path[0]
print tempfile.gettempdir()
tempfile.tempdir = os.getcwd()
tmpdir = tempfile.mkdtemp()
print tempfile.gettempdir()
cwd_save = os.getcwd()
print os.getcwd()
os.chdir(tmpdir)
print '=========%s=========' % os.getcwd()
os.chdir(cwd_save)
print os.getcwd()
shutil.rmtree(tmpdir, ignore_errors=True)
types=['rar','zip','tar','gz'] files=['luther.rar','gliethttp.zip','a.tar','b.gz'] print zip(types,files)
print os.path.abspath(sys.argv[0]) shutil.copyfile(os.path.abspath(sys.argv[0]), 'bakefile.py')
subprocess.call('ls') subprocess.call(['ls','-l']) os.system('ls') os.system('ls -l')
print '''hello hello 1.luther 2.gliethttp 3.china '''
|