Beispiel #1
0
def dir_reset(fullPath = None):
    """
    Delete any or children index files of fullPath.
    @param fullPath replaces with ROOT if it is None.:  
    """    
    
    if fullPath is None :
        fullPath = config.ROOT
        
    if fullPath == config.ROOT :
        info("index.dir.reset.full : start")
    
    dir_del(fullPath)            
    for child in os.listdir(fullPath) :
        try : 
            childPath = fullPath + os.path.sep + child
            if os.path.isfile(childPath) : continue
            
            dir_reset(childPath)
        except Exception as err :  
            error("index.dir.reset : " + err.__str__())
    
    if fullPath == config.ROOT :
        ok("index.dir.reset.full : finished")
        
    return True
Beispiel #2
0
    def load(self):
        try:
            info("Load configuration...")
            fp = None
            fp = open(os.path.join(BASE_DIR, "CELLAR/CELLAR.conf"))
            conf = json.load(fp)
            for key in conf:
                value = conf[key]
                if value == "true":
                    value = True
                elif value == "false":
                    value = False

                # globals()[key] = value
                vars(self)[key] = value
                # info("%30s = %s" % (key, value))
                info("{0:30s} = {1}".format(key, value))

                # for line in conf :
                #     match = re.search("(?P<param>[a-zA-Z_]*)\s*=\s*(?P<value>.*)", line)
                #     if not match :  continue
                #     param = match.group("param")
                #     value = match.group("value")
            ok("Load successfully!")
        except Exception as err:
            warn("Configuration file is not exists or broken.")
        finally:
            if fp: fp.close()
Beispiel #3
0
 def load(self) :
     try :
         info("Load configuration...")
         fp = None
         fp = open(os.path.join(BASE_DIR, "CELLAR/CELLAR.conf"))
         conf = json.load(fp)
         for key in conf :
             value = conf[key]
             if value == "true" :
                 value = True
             elif value == "false" :
                 value = False
             
             # globals()[key] = value
             vars(self)[key] = value
             # info("%30s = %s" % (key, value))
             info("{0:30s} = {1}".format(key, value))
         
             
             # for line in conf :
             #     match = re.search("(?P<param>[a-zA-Z_]*)\s*=\s*(?P<value>.*)", line)
             #     if not match :  continue
             #     param = match.group("param")
             #     value = match.group("value")
         ok("Load successfully!")                
     except Exception as err :
         warn("Configuration file is not exists or broken.")
     finally:
         if fp : fp.close()
Beispiel #4
0
def deleteFiles(request, *args, **kwargs): 
    """
    return {
        ...
        exts : [(ext, errno), ...]
    }
     
    0 : 성공
    1 : 대상이 경로입니다
    2 : -
    3 : 허용되지 않은 요청입니다
    4 : 오류가 발생하였습니다
    5 : 권한 없음
    """     
    groupPath   = request.POST.get("groupPath")
    exts        = request.POST.getlist("exts[]")
     
      
    targetPath  = os.path.normpath(os.path.dirname(groupPath)) + "/"
    filegroup   = os.path.basename(groupPath)
    filenames   = []
    for ext in exts :
        filenames.append(filegroup + ext)
     
    fileManager = CELLAR_FileManager(request)
    resultSet   = fileManager.rmfiles(targetPath, filenames)
    result      = []
    code        = 0
    
    info("file.delete : {0}".format(fileManager.getFullPath(groupPath))) 
    for row in resultSet :
        ext = os.path.splitext(row[0])[1]
        result.append((ext, row[1]))
        if row[1] == 0 :
            ok("file.delete : {0}".format(ext))
        else :
            error("dir.delete : E{0} {1}".format(code, ext))
        
        if row[1] is not 0 :
            code = row[1]
     
    message = {
        0 : "성공",
        1 : "대상이 경로입니다",
        2 : "",
        3 : "허용되지 않은 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한 없음"
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "groupPath" : groupPath,
        "result"    : result  
    }
    return HttpResponse(json.dumps(response))
Beispiel #5
0
def dir_del(fullPath):
    """
    Delete index file of fullPath. Will return False unless it is done successfully.
    """
    indexPath = os.path.normpath(fullPath + config.INDEX_FILE)
    try :
        os.remove(indexPath)
        ok("index.dir.del : " + fullPath )
        return True
    except Exception as err :
        # error("index.dir.del : " + err.__str__())
        return False
Beispiel #6
0
def createDir(request, *args, **kwargs):
    """
    * Common 
    0 : "SUCCESS",
    1 : "생성 위치가 존재하지 않습니다",
    2 : "생성 위치가 파일입니다",
    3 : "허용되지 않는 요청입니다",
    4 : "오류가 발생하였습니다",
    5 : "권한이 없습니다",
     
    * Additional 
    newPath : 생성된 새 경로 
    """
    
    parentPath  = request.POST.get("parentPath")
    dirName     = request.POST.get("dirName")
    newPath     = parentPath + dirName + "/"
    
    fileManager = CELLAR_FileManager(request) 
    code = fileManager.mkdir(parentPath, dirName)
          
    message = {
        0 : "SUCCESS",
        1 : "생성 위치가 존재하지 않습니다",
        2 : "생성 위치가 파일입니다",
        3 : "허용되지 않는 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한이 없습니다",
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "newPath"   : newPath,
    }
    
    if code == 0 :
        ok("dir.create : {0}".format(fileManager.getFullPath(newPath)))
    else :
        error("dir.create : E{0} {1}".format(code, fileManager.getFullPath(newPath)))
    return HttpResponse(json.dumps(response)) 
Beispiel #7
0
def deleteDir(request, *args, **kwargs):
    """
    0 : 성공
    1 : 대상이 파일입니다
    2 : -
    3 : 허용되지 않은 요청입니다
    4 : 오류가 발생하였습니다
    5 : 권한 없음
    """
     
    dirPath = request.POST.get("dirPath")
    
     
    fileManager = CELLAR_FileManager(request) 
    code = fileManager.rmdir(dirPath)
     
    message = {
        0 : "성공",
        1 : "대상이 파일입니다",
        2 : "",
        3 : "허용되지 않은 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한 없음"
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "dirPath"   : dirPath  
    }
    
    if code == 0 :
        ok("dir.delete : {0}".format(fileManager.getFullPath(dirPath)))
    else :
        error("dir.delete : E{0} {1}".format(code, fileManager.getFullPath(dirPath)))
        
    return HttpResponse(json.dumps(response))    
Beispiel #8
0
def userCreate(params, isAdmin = False) :
    response = {
        "code"  : 0,
    }
              
    is_group    = params.get('is_group')
    username    = params.get('username')
    password    = params.get("password")
    email       = params.get("email")
    first_name  = params.get("first_name")
    memo        = params.get("memo")
          
    # 최고 관리자에 의해 등록되는 ID 는 E-MAIL 은 필요 없음
    if not email and isAdmin :
        email = "" 
            
    if is_group and not isAdmin :
        response["code"]    = -2
        response["message"] = "그룹 사용자는 관리자만이 추가할 수 있습니다."
    elif not re.match("[a-zA-Z0-9_]{6,}|@[a-zA-Z0-9_]{5,}", username) :
        response["code"]    = -3
        response["message"] = "ID 는 6글자 이상의 영숫자와 '_' 로 작성해주세요."
    elif is_group and not re.match("@.*", username) :
        response["code"]    = -4
        response["message"] = "그룹 사용자의 아이디는 @로 시작해야합니다."
    elif username and password and first_name and ( email or isAdmin ) :
        try :
            usertype = UserInfo.NORMAL
            if is_group :
                usertype = UserInfo.GROUP
                     
            user        = User.objects.create_user(username, email, password, first_name=first_name)
            userinfo    = UserInfo(username=username, usertype=usertype, memo=memo)
            userinfo.save()
              
            response["code"]    = 0
            response["message"] = "사용자가 등록되었습니다."
            response["user"]    = user
            
            ok("user.create : " + username)
        except Exception as err :
            error("user.create : " + err.__str__())
            response["code"]    = 1
            response['message'] = "이미 존재하는 아이디 입니다."
    else :
        response["code"]    = -1
        response["message"] = "필수 항목을 모두 입력하여 주십시오."
        
    if isAdmin and is_group :
        response["is_group"] = is_group
        
    if username :
        response["username"] = username
            
    if email :
        response["email"] = email
        
    if first_name :
        response["first_name"] = first_name
        
    if memo :
        response["memo"] = memo
        
    return response