Пример #1
0
def doCopyFile(dirname, fname, src, dst) :
    fgCopied = False ;
    if fname != TEMP_FILE_TIME_STAMP :
        dstPath = dst + dirname.replace(src, '') ;
        if PSFile.isExist(dstPath) == False :
            os.makedirs(dstPath) ;
        srcFile = dirname + DELIMETER_DIR + fname ;
        dstFile = dstPath + DELIMETER_DIR + fname ;
        # Make symlink for file
        if os.path.islink(srcFile) and PSFile.isExist(dstFile) == False :
            doSymlink(srcFile, os.readlink(srcFile), src, dst) ;
        # Copy file
        elif PSFile.isExist(dstFile) == False or PSFile.getSize(srcFile) != PSFile.getSize(dstFile) :
            DBG('%s > %s' % (srcFile, dstFile)) ;
            shutil.copy(srcFile, dstFile) ;
            fgCopied = True ;
    return fgCopied ;
Пример #2
0
def doSymlink(dirname, linkto, src, dst) :
    if linkto[0] != DELIMETER_DIR :
        dstPath = dst + dirname.replace(src, '') ;
        # print dstPath ;
        if PSFile.isExist(dstPath) == False :
            os.symlink(linkto, dstPath) ;
    else :
        DBG('Skipped symlink of a absolute path, %s(%s).' % (dirname, linkto))
Пример #3
0
 def __init__(self, dbPath) :
     if not PSFile.isExist(dbPath) :
         raise IOError('ERR] Not exist "%s" file' % dbPath) ;
     self.m_conn = sqlite3.connect(dbPath) ;
     self.doCheckDB()
Пример #4
0
def getDiffTime(options, args) :
    try :
        lastTime = float(PSFile.readFile(options.tmpFile)) if PSFile.isExist(options.tmpFile) else 0.0 ;
    except ValueError :
        lastTime = 0.0 ;
    return (time.time() - lastTime) / 60 ;
Пример #5
0
    parser = OptionParser(usage=_usage, version=_version) ;
    parser.add_option('--exclude-dir', dest='exclude_dir', metavar='FOLDER[,...]', action='store', help='copy files excluding specific folders with seperating by comma.') ;
    parser.add_option('--timeout-min', type='float', metavar='N', dest='timeout_min', action='store', help='copy files if it has passed N minutes since the last copy.') ;
    (options, args) = parser.parse_args() ;

    if len(args) != 2 :
        ERR('Not Enough Parameters') ;
        print '\n' + _usage.replace('%prog', sys.argv[0]) ;
        raise SystemExit(exitCode) ;
    if args[0] == args[1] or os.path.abspath(args[0]) == os.path.abspath(args[1]) :
        ERR('Cannot copy into itself.') ;
        raise SystemExit(exitCode) ;
    if os.path.isdir(args[0]) == False :
        ERR('It is not directory, %s.' % args[0]) ;
        raise SystemExit(exitCode) ;
    if PSFile.isExist(args[0]) == False :
        ERR('Cannot access %s folder' % args[0]) ;
        raise SystemExit(exitCode) ;
    options.tmpFile = '%s/%s' % (args[0],TEMP_FILE_TIME_STAMP) ;

    if options.timeout_min and options.timeout_min > getDiffTime(options, args) :
        print 'Not %s minutes elapsed.' % options.timeout_min ;
        raise SystemExit(0) ;

    while args[0][len(args[0])-1] == DELIMETER_DIR :
        args[0] = args[0][:-1] ;

    # Just for debugging
    # print options ;
    # print args ;