Exemplo n.º 1
0
    def setNode(self, targetPath, properties):
        self.target = os.path.basename(targetPath)
        self.parent = os.path.basename(os.path.split(targetPath)[0])
        readOnly = bdd().getNode(self.target)
        try:
            if readOnly:
                self.properties = properties
                self.validator = {}
                for keys, values in readOnly['properties'].items():
                    for k, v in values.items():
                        self.validator[k] = v
                newProp = set(self.properties)
                oldProp = set(self.validator)
                propDict = bdd().getPropertiesDict()
                for key in newProp.intersection(oldProp):
                    propDict[key] = deepcopy(self.properties[key])
                    if readOnly['properties'][key]['readonly'] not in ["true", "True"]:
                        bdd().updateMeta(targetPath, key, propDict[key])
                #else:
                #   print("readOnly", key, propDict[key] )
            # else:
            #     for key in self.properties:
            #         print("clé", key, self.properties[key])
            #         if self.properties[key]['readOnly']:
            #             if self.properties[key]['readOnly'] != '':
            #                 bdd().updateMeta(target, key, self.properties[key])
            #             else:
            #                 self.properties[key]['readOnly'] = "false"
            #                 bdd().updateMeta(target, key, self.properties[key])
            #         else:
            #             self.properties[key]['readOnly'] = "false"
            #             bdd().updateMeta(target, key, self.properties[key])

        except CursorNotFound as e:
            return e
Exemplo n.º 2
0
    def getNode(self, targetPath):
        # Retourne la représentation de la node
            self.target = os.path.basename(targetPath)
            self.parent = "nodes/"+os.path.basename(os.path.split(targetPath)[0])
            meta = bdd().getNode(self.target)
            if meta:
                # type = ''
                # if os.path.isfile(targetPath):
                #     type = 'StructuredDataNode'
                # elif os.path.isdir(targetPath):
                #     type = 'ContainerNode'
                self.node = {
                     # os.path.basename(targetPath) : type,
                        'children' : [],
                        'properties' : {},
                        'accepts' : {},
                        'provides' : {},
                        'busy': '',
                        }

                cursor = bdd().getChildrenNode(self.target)
                if cursor:
                    for items in cursor:
                        self.node['children'].append(items)
                self.node['busy'] = meta['busy']
                self.node['path'] = deepcopy(meta['path'])
                self.node['properties'] = deepcopy(meta['properties'])
                self.node['accepts'] = deepcopy(meta['accepts'])
                self.node['provides'] = deepcopy(meta['provides'])
                return xml().xml_generator('get', self.node)
            else :
                return FileNotFoundError
Exemplo n.º 3
0
 def copyNode(self, targetPath, locationPath):
     # Copie la node et ses enfants
     self.loc = locationPath
     temp = {}
     try:
         cursor = bdd().getNode(targetPath)
         for items in cursor:
             for keys, values in items.items():
                 temp[keys] = values
     except:
         pass
     try:
         shutil.copytree(targetPath, self.loc)
         if temp:
             temp['path'] = self.loc
             temp['node'] = os.path.basename(self.loc)
             temp['properties']['mtime'] = {
                 "mtime": "Modified "+datetime.fromtimestamp(os.path.getmtime(targetPath)).strftime(
                     "%Y-%m-%d %H:%M:%S"), "readOnly" : "True"}
             temp['properties']['ctime'] = {
                 "ctime": "MetaData modified "+datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "readOnly" : "True"}
             temp['properties']['btime'] = {
                 "btime": "Creation date "+datetime.fromtimestamp(os.path.getctime(targetPath)).strftime(
                     "%Y-%m-%d %H:%M:%S"), "readOnly" : "True"}
             bdd().insertDB(temp)
     except shutil.Error as e:
         print('Directory not copied. Error: %s' % e)
         # Copie au même emplacement
     except OSError as e:
         print('Directory not copied. Error: %s' % e)
Exemplo n.º 4
0
def populateMeta():
    meta = [{
        'name': 'PROPERTIES',
        'metadata': PROPERTIES,
        'service': 'vospace'
    }, {
        'name': 'PROTOCOL',
        'metadata': PROTOCOL,
        'service': 'vospace'
    }, {
        'name': 'propertiesdict',
        'metadata': PropertiesDict,
        'service': 'vospace'
    }, {
        'name': 'voprotocols',
        'metadata': {
            'accepts': {
                'get': 'ivo://ivoa.net/vospace/core#httpget',
                'put': 'ivo://ivoa.net/vospace/core#httpput'
            },
            'provides': {
                'get': 'ivo://ivoa.net/vospace/core#httpget',
                'put': 'ivo://ivoa.net/vospace/core#httpput'
            }
        },
        'service': 'vospace'
    }, {
        'name': 'voviews',
        'metadata': {
            'accepts': {
                'anyview': 'ivo://ivoa.net/vospace/core#anyview',
                'fits': 'ivo://ivoa.net/vospace/core#fits',
                'votable': 'ivo://ivoa.net/vospace/core#votable'
            },
            'provides': {
                'default': 'ivo://ivoa.net/vospace/core#defaultview',
                'fits': 'ivo://ivoa.net/vospace/core#fits',
                'votable': 'ivo://ivoa.net/vospace/core#votable'
            }
        },
        'service': 'vospace'
    }, {
        'name': 'voproperties',
        'metadata': {
            'accepts': {},
            'provides': {},
            'contains': {
                'date': 'ivo://ivoa.net/vospace/core#date'
            }
        },
        'service': 'vospace'
    }]
    for items in meta:
        bdd().insertDB(items)
    print("VOSpace property list OK")
    print("VOSpace protocol list OK")
    print("VOSpace view list OK")
    print("Service's metadata ready")
Exemplo n.º 5
0
 def deleteNode(self, targetPath):
     # Supprime la node et ses enfants
     try:
         self.target = os.path.basename(targetPath)
         self.parent = os.path.basename(os.path.split(targetPath)[0])
         if os.path.exists(targetPath):
             if os.path.isdir(targetPath):
                 shutil.rmtree(targetPath)
             elif os.path.isfile(targetPath):
                 os.remove(targetPath)
             try:
                 bdd().connexion().delete_one({'node': self.target, 'parent': self.parent})
                 bdd().connexion().delete_many({'parent': self.target})
             except CursorNotFound:
                 return False
     except FileNotFoundError:
         raise
Exemplo n.º 6
0
 def createNode(self, dictionary):
     # Creation de la node
     try:
         self.target = dictionary['cible']
         self.path = dictionary['path']
         if not bdd().getNode(self.target):
             try:
                os.makedirs(self.path+"/"+self.target)
             except OSError as e:
                 return 'Directory creation failed. Error %s' % e
             try:
                 if os.path.exists(self.path+"/"+self.target):
                     bdd().insertDB(fsToDictionary(self.path+"/"+self.target))
                     self.setNode(self.path+"/"+self.target, dictionary['properties'])
             except OSError as e:
                 return 'BDD update failed. Error %s' % e
         return True
     except FileExistsError as e:
         return e
Exemplo n.º 7
0
def fsToDictionary(path):
    tempdate = datetime.fromtimestamp(os.path.getmtime(path))
    mdate = tempdate.strftime("%Y-%m-%d %H:%M:%S")
    owner = str(os.stat(path).st_uid)
    fName = os.path.basename(path)

    hierarchy = {
        'node': fName,
        'path': path,
        'ownerId': owner,
        'busy': "False",
        'properties': bdd().getPropertiesDict(),
        'parent':
        os.path.basename(os.path.abspath(os.path.join(path, os.pardir))),
        'ancestor': [],
        'accepts': [],
        'provides': [],
    }
    hierarchy['properties']['mtime'] = {
        "mtime": "Modified " + mdate,
        'readonly': "True"
    }
    hierarchy['properties']['ctime'] = {
        "ctime":
        "MetaData modified " + datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
        'readonly':
        "True"
    }
    hierarchy['properties']['btime'] = {
        "btime":
        "Creation date " + datetime.fromtimestamp(
            os.path.getctime(path)).strftime("%Y-%m-%d %H:%M:%S"),
        'readonly':
        "True"
    }
    if os.path.isdir(path):
        hierarchy['properties']['type'] = {
            'type': 'ContainerNode',
            'readonly': "True"
        }
    elif os.path.isfile(path):
        hierarchy['properties']['type'] = {
            'type': 'DataNode',
            'readonly': "True"
        }
    hierarchy['size'] = octet(os.path.getsize(path))
    mathusalem = path.split(os.sep)
    list = [
        ".", "VOTest", "VOSpace", "nodes", hierarchy['parent'],
        hierarchy['node']
    ]
    for items in mathusalem:
        if items not in list:
            hierarchy['ancestor'].append(items)
    return hierarchy
Exemplo n.º 8
0
def startup():
    if bdd.connexion(bdd()).find({"service": "vospace"}).count() == 0:
        populateMeta()
    if bdd.connexion(bdd()).find({"node": {'$exists': True}}).count() == 0:
        populateFiles()
        print("Database ready")
    else:
        # TO DO : Comparaison FS et DB au lancement.
        # database = []
        # FS = []
        # cursor = bdd.connexion(bdd()).find({'node': { '$exists' : True }},{'_id': False})
        # for items in cursor:
        #     database.append(items)
        # for items in os.listdir("./VOTest/VOSpace/nodes/"):
        #     for dir, subdirs, files in os.walk("./VOTest/VOSpace/nodes/" + items):
        #         for x in subdirs:
        #             FS.append(fsToDict(os.path.join(dir, x)))
        #         for y in files:
        #             FS.append(fsToDict(os.path.join(dir, y)))
        print("Database : OK")
Exemplo n.º 9
0
 def getVOSpaceSettings(self, meta):
     retour = {}
     coll = bdd().connexion()
     curseur = coll.find({'name': 'vo'+meta})
     if curseur:
         for documents in curseur:
             for keys, values in documents.items():
                 if keys == "metadata":
                     for k, v in values.items():
                             retour[k] = v
     return xml().xml_generator(meta, retour)
Exemplo n.º 10
0
def populateFiles():
    for dir, subdirs, files in os.walk(RACINE):
        for x in subdirs:
            bdd.insertDB(bdd(), fsToDictionary(os.path.join(dir, x)))
        for y in files:
            bdd.insertDB(bdd(), fsToDictionary(os.path.join(dir, y)))