Example #1
0
 def pathexist(self, path=""):
     cmd = template(info, path=path)
     err, status = commands.getstatusoutput(cmd)
     if err == 512:
         return False
     else:
         return True
Example #2
0
 def groupexist(self, group=""):
     cmd = template(grep, group=group)
     err, status = commands.getstatusoutput(cmd)
     if status:
         return True
     else:
         return False
Example #3
0
 def _getinfo(self, path):
     cmd = template(info, path=path)
     err, att = commands.getstatusoutput(cmd)
     if err != 0:
         error = "A error arise go get '" + path + "' info"
         log.error(error)
         return {"path": path,
                 "jurisdiction": "",
                 "hardlinkorsub": "",
                 "owner": "",
                 "group": "",
                 "size": "",
                 "changetime": "",
                 }
     att = att.split(" ")
     if "d" not in att[0]:
         warning = "the path you input is not a direction"
         log.warning(warning)
         return {"path": path,
                 "jurisdiction": "",
                 "hardlinkorsub": "",
                 "owner": "",
                 "group": "",
                 "size": "",
                 "changetime": "",
                 }
     try:
         jurisdiction = att[0]
         hardlinkorsub = int(att[1])
         owner = att[2]
         group = att[3]
         size = int(att[4])
         if att[6] == "":
             changetime = (att[5], att[7], att[8])
         else:
             changetime = (att[5], att[6], att[7])
         print att[8]
     except Exception as e:
         error = "A error arise when get attribute of dir " + path + str(e)
         log.error(error)
         return {"path": path,
                 "jurisdiction": "",
                 "hardlinkorsub": "",
                 "owner": "",
                 "group": "",
                 "size": "",
                 "changetime": "",
                 }
     return {"path": path,
             "jurisdiction": jurisdiction,
             "hardlinkorsub": hardlinkorsub,
             "owner": owner,
             "group": group,
             "size": size,
             "changetime": changetime
             }
Example #4
0
 def _aclinfo(self, path=""):
     cmd = template(getacl, path=path)
     d, t = commands.getstatusoutput(cmd)
     if d != 0:
         err = "a error arise when do cmd (" + cmd + ")" + " :\n" + t + " "
         log.error(err)
         return {}
     a = t.splitlines()
     temp = dict()
     temp["file"] = a[0].split(":")[1].strip(" ")
     temp["owner"] = a[1].split(":")[1].strip(" ")
     temp["owner's group"] = a[2].split(":")[1].strip(" ")
     temp["default mask"] = None
     temp["mask"] = None
     temp["default group"] = []
     temp["group"] = []
     temp["default user"] = []
     temp["user"] = []
     temp["default other"] = None
     temp["other"] = None
     for i in range(0, 3):
         del a[0]
     for e in a:
         f = e.split(":")
         g = False
         if f[0] == "default":
             g = True
             del f[0]
         if f[0] == "user":
             h = "user"
             del f[0]
         if f[0] == "group":
             h = "group"
             del f[0]
         if f[0] == "other":
             h = "other"
             del f[0]
         if f[0] == "mask":
             h = "mask"
             del f[0]
         if len(f[1].split("\t")) == 2:
             del f[1]
         if f[0] == "":
             if h == "user":
                 f[0] = temp["owner"]
             elif h == "mask":
                 if g:
                     temp["default mask"] = f[1]
                 else:
                     temp["mask"] = f[1]
                 continue
             elif h == "other":
                 if g:
                     temp["default other"] = f[1]
                 else:
                     temp["other"] = f[1]
                 continue
             else:
                 f[0] = temp["owner's group"]
         elif h == "user":
             if f[0] == temp["owner"]:
                 continue
         elif h == "group":
             if f[0] == temp["owner's group"]:
                 continue
         else:
             pass
         j = dict()
         j[f[0]] = f[1]
         if g:
             h = "default " + h
         temp[h].append(j)
     return temp