示例#1
0
 def create_dependency(self, name, dep_id, rev_id=-1):
     """
     Add a new dependency
     """
     dep_id = int(dep_id)
     try:
         dep = DBSession.query(GameDepPage).filter_by(gamedeptype="dep", 
                                                      id=dep_id).one()
         if rev_id != -1:
             rev = DBSession.query(GameDepRevision).filter_by(
                                         id=rev_id).one()
         else:
             if dep.revisions.count() > 0:
                 rev = dep.revisions[0]
             else:
                 raise GameDepNotFound
         if not rev in dep.revisions:
             raise GameDepNotFound
     except NoResultFound:
         raise GameDepNotFound
     
     page = self.show(name, no_revision_error=False)[0]
     for pagedep in page.dependencies:
         if pagedep.page.id == dep.id:
             raise GameDepFound
     page.dependencies.append(rev)
示例#2
0
 def update_binary(self, name, revision, binary_id, operatingsystem, 
                   architecture, binary, request):
     """
     Update a binary
     """
     try:
         if not binary:
             os_obj = DBSession.query(OperatingSystems).filter_by(
                                                 id=operatingsystem).one()
             arch_obj = DBSession.query(Architectures).filter_by(
                                                 id=architecture).one()
     except NoResultFound:
         raise GameDepNotFound
     
     rev = self.show(name, revision)[1]
     bin_obj = None
     for x in rev.binary:
         if x.id == int(binary_id):
             bin_obj = x
             break
     if not bin_obj:
         raise GameDepNotFound
     
     if not binary:
         bin_obj.operatingsystem_obj = os_obj
         bin_obj.architecture_obj = arch_obj
     else:
         file_lib = FileLib(request)
         old_name = bin_obj.file_obj.name
         old_mimetype = bin_obj.file_obj.mimetype
         aio_obj = file_lib.write(old_name, binary, old_mimetype)
         file_lib.delete(bin_obj.file_obj)
         bin_obj.file_obj = aio_obj
示例#3
0
 def list_architectures(self, with_display_name=True):
     """
     Get a Architecture list from database.
     """
     if with_display_name:
         archlist = DBSession.query(Architectures.id, 
                                 Architectures.display_name).order_by(
                                 Architectures.id).all()
         archlist = [(x[0], x[1]) for x in archlist]
     else:
         archlist = DBSession.query(Architectures.id).order_by(
                                 Architectures.id).all()
         archlist = [x[0] for x in archlist]
     return archlist
示例#4
0
 def list_operatingsystems(self, with_display_name=True):
     """
     Get a Operating System list from database.
     """
     if with_display_name:
         oslist = DBSession.query(OperatingSystems.id, 
                                 OperatingSystems.display_name).order_by(
                                 OperatingSystems.id).all()
         oslist = [(x[0], x[1]) for x in oslist]
     else:
         oslist = DBSession.query(OperatingSystems.id).order_by(
                                 OperatingSystems.id).all()
         oslist = [x[0] for x in oslist]
     return oslist
示例#5
0
 def show(self, name, revision=None, no_revision_error=True):
     """
     Get article of a page or revision
     Raise GameDepNotFound if page does not exist
     """
     if revision:
         revision = int(revision)
     if not name:
         raise GameDepNotFound
     
     if not revision:
         try:
             page = DBSession.query(GameDepPage).filter_by(
                                             name=name,
                                             gamedeptype=self.gamedep_type
                                             ).one()
         except NoResultFound:
             raise GameDepNotFound("NoResultFound")
         if not page.revisions.count() and no_revision_error:
             raise GameDepNotFound("no_revision_error")
         return (page, page.revisions)
     else:
         try:
             page, rev = self.show(name)
             rev_result = rev.filter_by(id=revision).one()
             return (page, rev_result)
         except NoResultFound:
             raise GameDepNotFound
示例#6
0
 def revision_dropdown(self, dep_id, with_display_name=True):
     initial_item = [("-1", "Use Latest Version")]
     if with_display_name:
         rev = DBSession.query(GameDepRevision.id, 
                                GameDepRevision.version).filter_by(
                                         page_id=dep_id, published=True)
     else:
         rev = DBSession.query(GameDepRevision.id).filter_by(
                                         page_id=dep_id, published=True)
     result = initial_item 
     result.extend(rev.all())
     if with_display_name:
         result = [(str(x[0]), str(x[1])) for x in result]
     else:
         result = [str(x[0]) for x in result]
     return result
示例#7
0
 def show_binary(self, binary_id):
     try:
         bin_obj = DBSession.query(GameDepBinary).filter_by(
                                         id=binary_id).one()
     except NoResultFound:
         raise GameDepNotFound
     return bin_obj
示例#8
0
 def create_binary(self, name, revision, operatingsystem, architecture, 
                   binary, mimetype, filename, request):
     """
     Add a new binary
     """
     try:
         os_obj = DBSession.query(OperatingSystems).filter_by(
                                             id=operatingsystem).one()
         arch_obj = DBSession.query(Architectures).filter_by(
                                             id=architecture).one()
     except NoResultFound:
         raise GameDepNotFound
     
     rev = self.show(name, revision)[1]
     file_lib = FileLib(request)
     aio_obj = file_lib.write(filename, binary, mimetype)
     bin_obj = GameDepBinary(aio_obj, os_obj, arch_obj)
     rev.binary.append(bin_obj)
示例#9
0
 def list(self): #@ReservedAssignment
     """
     List all the pages
     """
     result = set()
     gamedeps = DBSession.query(GameDepPage).filter_by(
                             gamedeptype=self.gamedep_type)
     if not gamedeps:
         raise GameDepNotFound
     for gamedep in gamedeps:
         result.add(gamedep.name)
     return result
示例#10
0
 def dependency_dropdown(self, with_display_name=True):
     result = []
     page = DBSession.query(GameDepPage).filter_by(gamedeptype="dep")
     for x in page:
         if x.revisions.count():
             i = 0
             for revision in x.revisions:
                 if revision.published:
                     i += 1
             if i > 0:
                 if with_display_name:
                     result.append((str(x.id), 
                                    "%s (%s)" % (x.display_name, 
                                                 x.name)))
                 else:
                     result.append(str(x.id))
     return result
示例#11
0
    def exists(self, name, version=None, raise_if_found=False):
        """
        Check to see if a page exists
        Return True/False
        """
        try:
            page = DBSession.query(GameDepPage).filter_by(
                name=name, gamedeptype=self.gamedep_type).one()
        except NoResultFound:
            return False

        if version:
            versions = [x.version for x in page.revisions]
            if not version in versions:
                return False
        if raise_if_found:
            raise GameDepFound
        return True
示例#12
0
 def exists(self, name, version=None, raise_if_found=False):
     """
     Check to see if a page exists
     Return True/False
     """
     try:
         page = DBSession.query(GameDepPage).filter_by(
                                         name=name,
                                         gamedeptype=self.gamedep_type
                                         ).one()
     except NoResultFound:
         return False
     
     if version:
         versions = [x.version for x in page.revisions]
         if not version in versions:
             return False
     if raise_if_found:
         raise GameDepFound
     return True
示例#13
0
 def list_categories(self):
     """
     List the boards categories
     """
     categories = DBSession.query(BBCategory)
     return categories
示例#14
0
 def show_json(self):
     """
     Serialise gamedep into json
     """
     root = {"operatingsystems": [], 
             "architectures": [],
             "gamedep": []}
     key = None
     gametype = "game"
     deptype = "dep"
     game = DBSession.query(GameDepPage).filter_by(gamedeptype=gametype
                                                   ).all()
     dep = DBSession.query(GameDepPage).filter_by(gamedeptype=deptype).all()
     oslist = DBSession.query(OperatingSystems)
     archlist = DBSession.query(Architectures)
     for os in oslist:
         osdict = {}
         osdict["name"] = os.name
         osdict["display_name"] = os.display_name
         root["operatingsystems"].append(osdict)
     for arch in archlist:
         archdict = {}
         archdict["name"] = arch.name
         archdict["display_name"] = arch.display_name
         root["architectures"].append(archdict)
     for gamedep in [game, dep]:
         if gamedep == game:
             key = "game"
         else:
             key = "dependency"
         for item in gamedep:
             if item.revisions.count() == 0:
                 continue
             gamedepdict = {}
             gamedepdict["name"] = item.name
             gamedepdict["display_name"] = item.display_name
             gamedepdict["description"] = item.description
             gamedepdict["created"] = str(item.created)
             gamedepdict["dependencies"] = []
             for loopdep in item.dependencies:
                 depdict = {}
                 if loopdep.page.revisions.count() == 0:
                     continue
                 depdict['dependency'] = loopdep.page.name
                 if loopdep:
                     depdict['version'] = str(loopdep.version)
                 else:
                     depdict['version'] = str(loopdep.page.\
                                              revisions[0].version)
                 gamedepdict["dependencies"].append(depdict)
             gamedepdict["tags"] = []
             for looptag in item.tags:
                 if looptag.name.strip():
                     gamedepdict["tags"].append(looptag.name)
             gamedepdict["pictures"] = []
             if self.gallery:
                 album = self.gallery.show_album(item.album_id)
                 for pic in album.pictures:
                     picture = {}
                     picture['url'] = (self.uploadurl + pic.file_obj.uuid +
                                       "/" + pic.file_obj.name)
                     thumb_name = (splitext(pic.file_obj.name)[0] +
                                   ".thumbnail.png")
                     picture['thumb_url'] = (self.uploadurl +
                                             pic.file_obj.uuid +
                                             "/" + thumb_name)
                     picture['thumb_name'] = thumb_name
                     picture['default'] = False
                     picture['display_name'] = pic.display_name
                     picture['description'] = pic.description
                     picture['uuid'] = pic.file_obj.uuid
                     picture['name'] = pic.file_obj.name
                     if album.default_picture == pic:
                         picture['default'] = True
                     gamedepdict["pictures"].append(picture)
             gamedepdict["revisions"] = []
             for looprev in item.revisions:
                 if looprev.published:
                     revdict = {}
                     revdict["version"] = str(looprev.version)
                     revdict["created"] = str(looprev.created)
                     revdict["moduletype"] = looprev.moduletype
                     if gamedep == game:
                         revdict["source"]=  self.uploadurl + \
                                             looprev.file_obj.uuid \
                                             + "/" + looprev.file_obj.name
                         revdict['source_uuid'] = looprev.file_obj.uuid
                         revdict['source_name'] = looprev.file_obj.name
                     revdict["binaries"] = []
                     for loopbin in looprev.binary:
                         bindict = {}
                         bindict["binary"] = self.uploadurl + \
                                             loopbin.file_obj.uuid \
                                             + "/" + loopbin.file_obj.name
                         bindict["operating_system"] = \
                                         loopbin.operatingsystem_obj.name
                         bindict["architecture"] = \
                                         loopbin.architecture_obj.name
                         bindict['uuid'] = loopbin.file_obj.uuid
                         bindict['name'] = loopbin.file_obj.name
                         revdict["binaries"].append(bindict)
                     gamedepdict["revisions"].append(revdict)
             root["gamedep"].append({key: gamedepdict})
     return json.dumps(root, sort_keys=True, indent=4)