Ejemplo n.º 1
0
 def returnBook(ret_book_item, ):
     for book in Catalog.books_list:
         if book == ret_book_item.book:
             book.book_item.append(ret_book_item)
             book.total_count += 1
     Catalog.clearIssuerInfo(ret_book_item)
     Catalog.removeFromissuedList(ret_book_item)
Ejemplo n.º 2
0
 def return_book(return_book_item):
     for book in Catalog.books_list:
         if book == return_book_item:
             book.book_item.append(return_book_item)
             book.total_count += 1
     Catalog.clear_member_issue_info(return_book_item)
     Catalog.remove_from_issue_list(return_book_item)
Ejemplo n.º 3
0
 def returnBook(self, name, Catalog):
     book = Catalog.searchByName(name)
     for self.items in self.issued_book:
         if book.book_item in self.issued_book:
             b2 = book.book_item
             self.issued_book.remove(book.book_item)
             Catalog.addBookItem(book, b2.isbn, b2.rack)
         print(name, "Book is returned")
Ejemplo n.º 4
0
 def returnBook(self, name, isbn, rack):
     for book in self.issuedbook_list:
         if isbn not in self.issuedbook_list:
             print(name, "No book found in the books")
         else:
             self.issuedbook_list.remove(isbn)
             Catalog.addBookItem(name, isbn, rack)
             print(name, "book returned successfully")
 def returnBook(self,ret_book_item, days):
     for book in Catalog.books_list:
         if book == ret_book_item.book:
             book.book_item.append(ret_book_item)
             book.total_count += 1
     Catalog.clearIssuerInfo(ret_book_item)
     Catalog.removeFromReservedList(ret_book_item)
     Billing.calcBill(days)
Ejemplo n.º 6
0
    def issueBook(self, name, Catalog, days=10):
        book = Catalog.searchByName(name)

        if len(book.book_item) > 0:
            b1 = book.book_item[0]
            self.issued_book.append(b1)
            Catalog.removeBookItem(name, b1.isbn)
            print(name, "book is isssued")
        else:
            print("Book is not available")
 def reserveBook(self,name, student_id, book_title, days):
     for book in Catalog.books_list:
         if book.title == book_title and len(book.book_item) != 0:
             book_item = book.book_item.pop()
             book.total_count -= 1
             Catalog.updateIssuerInfo(book_item, name, student_id, days)
             Catalog.addToReservedList(book_item)
             return book_item
     else:
         print("The book you're trying to reserve is unavailable.")
Ejemplo n.º 8
0
 def issue_book(name, student_id, book_title, days):
     for book in Catalog.books_list:
         if book.title == book_title and len(book.book_item) != 0:
             book_item = book.book_item.pop()
             book.total_count -= 1
             Catalog.update_member_issue_info(book_item, name, student_id,
                                              days)
             Catalog.add_to_issue_list(book_item)
             return book_item
     else:
         print(f"{book_title} is currently not available in the library")
Ejemplo n.º 9
0
    def returnBook(self, name, BookName):
        book_exist = Catalog.checkIfBookExistsByName(BookName)

        if book_exist:
            book_issued_by_user = Catalog.checkIfBookIssuedByMember(
                book_exist[0], self.student_id)

        if book_exist and book_issued_by_user:
            BookIssue.returnBook(book_exist[0], self.student_id)
        else:
            print('This book is not present in library')
Ejemplo n.º 10
0
def section_list(SITE):
    print('FUNCTION -> system-> calalog -> section -> list')

    SITE.addHeadFile('/templates/system/css/style.css')
    section_id = SITE.p[2]

    CATALOG = Catalog(SITE)
    SECTION = Section(SITE)
    section = SECTION.getSection(section_id)
    catalog = CATALOG.getItem(section['catalog_id'])

    # Breadcrumbs
    data = {}
    data['catalog_id'] = catalog['id']
    data['parent_id'] = section['parent_id']
    breadcrubmps_list = SECTION.breadcrumbsPath(data)[::-1]

    breadcrumbs = ''

    if (len(breadcrubmps_list) > 0):
        for i in breadcrubmps_list:
            breadcrumbs += '<svg><use xlink:href="/templates/system/svg/sprite.svg#arrow_right_1"></use></svg>'
            breadcrumbs += '<a href="/system/catalog/section/' + str(
                i['id']) + '">' + i['name'] + '</a>'

    rows = SECTION.getItems(section_id)

    row_out = ''
    if (rows):
        i = 1
        for row in rows:
            status_tr_class = ''
            if row['status'] == 0:
                status_tr_class = 'class="admin_table_tr_unpub"'

            row_out += f'''<tr { status_tr_class }>
                <td>{ i }</td>
                <td>
                    <div class="flex_row contextmenu_wrap">
                        <svg class="contextmenu_ico" title="Действия" data-id="{ row['id'] }">
                            <use xlink:href="/templates/system/svg/sprite.svg#menu_3"></use>
                        </svg>
                    </div>
                </td>
                <td><a href="/system/catalog/item/edit/{ row['id'] }">{ row['name'] }</a></td>
            </tr>'''
            i += 1

    SITE.content += f'''<div class="bg_gray">
Ejemplo n.º 11
0
    def merge(self):
        print "Merging files"
        merge_file = 'M{}'.format(str(uuid.uuid4()).split('-')[-1])
        merge_catalog = Catalog(merge_file)
        merged_tokens = {}


        reader1 = InvertedIndexReader(self.catalog1)
        reader2 = InvertedIndexReader(self.catalog2)
        catalog1_dict = self.catalog1.get()
        catalog2_dict = self.catalog2.get()

        for term_id, offsets in catalog1_dict.iteritems():
            if term_id in catalog2_dict:
                positions_catalog1 = reader1.readAsDict(term_id)
                positions_catalog2 = reader2.readAsDict(term_id)
                positions_catalog1.update(positions_catalog2)
                merged_tokens[term_id] = positions_catalog1
                self.catalog2.delete(term_id)

            else:
                merged_tokens[term_id] = reader1.readAsDict(term_id)

        for term_id, offsets in catalog2_dict.iteritems():
            merged_tokens[term_id] = reader2.readAsDict(term_id)


        merge_writer = InvertedIndexWriter(merged_tokens, merge_catalog, merge_file)
        merge_writer.write(encode=False)
        print "Merging done!"
        return merge_catalog
Ejemplo n.º 12
0
 def issueBook(self, name, days=10):
     book_exist = Catalog.checkIfBookExistsByName(name)
     if book_exist:
         BookIssue.issueBook(book_exist[-1], self.student_id, self.name,
                             days)
     else:
         print('Book is not available in library')
Ejemplo n.º 13
0
 def removeBook(self, name):
     #Check if the book by the given name exists
     book_name_exist = Catalog.checkIfBookExistsByName(name)
     if book_name_exist:
         Catalog.books.remove(book_name_exist[-1])
         Catalog.diff_count -= 1
     else:
         print('This book is not present in the library')
Ejemplo n.º 14
0
def testmod():
    import doctest
    global testEntry, testCatalog, testToHtml, testArchiveToHtml
    
    urn = 'urn:x-internet-archive:bookserver:catalog'
    testCatalog = Catalog(title='Internet Archive OPDS', urn=urn)
    testLink    = Link(url  = 'http://archive.org/download/itemid.pdf',
                       type = 'application/pdf', rel='http://opds-spec.org/acquisition/buying')
    catalogLink = Link(url = '/providers/IA', type = Link.opds)
    testEntry = Entry({'urn'  : 'x-internet-archive:item:itemid',
                        'title'   : u'test item',
                        'updated' : '2009-01-01T00:00:00Z',
                        'date': '1977-06-17T00:00:55Z',
                        'summary': '<p>Fantastic book.</p>',
                        },
                        links=[testLink])
                        
    start    = 0
    numFound = 2
    numRows  = 1
    urlBase  = '/alpha/a/'
    testNavigation = Navigation.initWithBaseUrl(start, numRows, numFound, urlBase)
    testCatalog.addNavigation(testNavigation)
    
    osDescription = 'http://bookserver.archive.org/catalog/opensearch.xml'
    testSearch = OpenSearch(osDescription)
    testCatalog.addOpenSearch(testSearch)
    
    testCatalog.addEntry(testEntry)
    testToHtml = CatalogToHtml(testCatalog)
    
    testArchiveToHtml = ArchiveCatalogToHtml(testCatalog)
    
    doctest.testmod()
Ejemplo n.º 15
0
    def __init__(self, env, floor):
        """
        Inits Inventory with the simulation environment and a reference to warehouse Floor layout

        During initialization, Inventory creates an instance of each Item in Catalog and distributes
        them across random Shelf objects within the warehouse

        Args:
            env: SimPy simulation environment
            floor: Floor object so we can communicate with this subset
        """
        self.clock = env
        self.floor = floor
        self.stock = []
        self.catalog = Catalog()

        self.populateStock()
        self.stockShelves()
Ejemplo n.º 16
0
    def __init__(self, id, title='', vocab_id=None, container=None):
        # ZCatalog no longer cares about vocabularies
        # so the vocab_id argument is ignored (Casey)

        if container is not None:
            self = self.__of__(container)
        self.id = id
        self.title = title

        # vocabulary and vocab_id are left for backwards
        # compatibility only, they are not used anymore
        self.vocabulary = None
        self.vocab_id = ''

        self.threshold = 10000
        self._v_total = 0

        self._catalog = Catalog()
Ejemplo n.º 17
0
 def issuedBook(
     name,
     student_id,
     book_name,
 ):
     for book in Catalog.books_list:
         if book.name == book_name and len(book.book_name) != 0:
             book_item = book.book_item.pop()
             book.total_count -= 1
             Catalog.updateIssuerInfo(
                 book_item,
                 name,
                 student_id,
             )
             Catalog.addToissuedList(book_item)
             return book_item
     else:
         print("This book is not available.")
Ejemplo n.º 18
0
 def returnBook(self, name, isbn, rack):
     for book in self.issuedbook_list:
         if isbn not in self.issuedbook_list:
             print("you are returning a wrong book")
         else:
             self.issuedbook_list.remove(isbn)
             Catalog.addBookItem(name, isbn, rack)
             days = int(
                 input(
                     "How many days has it been since you issued this book? Be honest! :"
                 ))
             d = 10
             if days > d:
                 print(
                     "You Have to pay fine of Rs.2/day for late submission",
                     name)
                 Catalog.addFine(days)
             else:
                 print("Thank You book returned successfully ", name)
                 print("Returned Book Name & isbn:", name, isbn)
Ejemplo n.º 19
0
    def show_videos_init(self):
        
        ok = True
        cpt = 0

        file = xbmc.makeLegalFilename(os.path.join(self.CACHEDIR,self.FILENAME))
        f = open(file,'w')
        
        pDialog = xbmcgui.DialogProgress()
        ret = pDialog.create( 'XBMC', __language__ ( 30200 ) )        
        pDialog.update(0, __language__ ( 30202 ) )
        
        catalog = Catalog()
        self.NB_VIDEO = catalog.videos.__len__();
                 
        for video in catalog.videos:                 
            f.write('\n'.join(['%s;%s;%s;%s' % (video[Catalog.TITLE_TAG].encode('utf-8'),video[Catalog.DATE_TAG].encode('utf-8'), video[Catalog.URL_TAG].encode('utf-8'), video[Catalog.IMAGE_TAG].encode('utf-8'))]))
          
            cpt=cpt+1

            paramsAddons = {}
            paramsAddons[self.PARAM_PLAY_VIDEO]  = "true"
            paramsAddons[self.PARAM_VIDEO_ID]    = video[Catalog.URL_TAG]
            url = _create_param_url( paramsAddons )
                            
            infoLabels={ "Title": video[Catalog.DATE_TAG] + " - " + video[Catalog.TITLE_TAG],
                         "Date": video[Catalog.DATE_TAG]}            
            
            paramsAddonsContextMenu = {}
            paramsAddonsContextMenu[self.PARAM_DOWNLOAD_VIDEO]  = "true"
            paramsAddonsContextMenu[self.PARAM_VIDEO_ID]    = video[Catalog.URL_TAG]
            paramsAddonsContextMenu[self.PARAM_VIDEO_NAME]    = video[Catalog.TITLE_TAG]
            
            urlContextMenu = _create_param_url( paramsAddonsContextMenu )
            
            cm = _addContextMenuItems(name=video[Catalog.TITLE_TAG], url=urlContextMenu, msg= __language__(30102))
            
            _addLink( name=video[Catalog.TITLE_TAG], url=url, iconimage=video[Catalog.IMAGE_TAG], itemInfoLabels=infoLabels, c_items=cm )

            pDialog.update(int(99*float(cpt)/(self.NB_VIDEO)), __language__ ( 30202 ) )            
       
        pDialog.close()
        
        f.close()
                
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_NONE)
        xbmcplugin.setPluginCategory( handle=int( sys.argv[ 1 ] ), category="referer" )
        xbmcplugin.setContent(int(sys.argv[1]), 'movies')
        _end_of_directory( True )

        return ok
Ejemplo n.º 20
0
    def returnBook(self, name):
        try:
            book = super().searchByName(name)
            isbn = list(filter(lambda x: x[0] == book, self.booksissued))[0][1]

            #checking for correlation between self.bookissued and
            #Library.lended_book_data to extract rack value.
            for i in self.booksissued:
                if i[0] == book:
                    for j in Librarian.lended_book_data.get(book):
                        if j[0] == isbn:
                            rack = j[1]

            #return book and update member variables.
            Catalog._addBookItem(self, book, isbn, rack)
            print(f"Book '{book}' returned.\n")
            #updating variables :->
            self.booksissued.remove((book, isbn))
            self.issuedbookcount -= 1
            self.bookitems.remove(isbn)

            #updating Librarian.lended_book_data
            for i in list(Librarian.lended_book_data.keys()):
                #remove individual lended bookitem data from dictionary.
                try:
                    lis = Librarian.lended_book_data.get(book)
                    for j in lis:
                        if isbn == j[0]:
                            Librarian.lended_book_data[book] = list(
                                filter(lambda x: x[0] != isbn, lis))
                            # remove book from dictionary if all the bookitems are returned.
                            if len(Librarian.lended_book_data.get(book)) == 0:
                                Librarian.lended_book_data.pop(i)
                except TypeError:
                    return

        except IndexError:
            print(f"{self.name},'{book}' is not in your inventory.\n")
Ejemplo n.º 21
0
def make_connection():
    catalog = Catalog(args.lang)
    f = os.path.join(ui.user_folder, 'database')
    if catalog.error:
        ui.on_error_data(catalog.error)
    else:
        try:
            with codecs.open(f, 'w', 'utf-8') as datalist:
                datalist.write('\n'.join([
                    '%s;%s;%s;%s' %
                    (video[Catalog.TITLE_TAG], video[Catalog.DATE_TAG],
                     video[Catalog.URL_TAG], video[Catalog.IMAGE_TAG])
                    for video in catalog.videos
                ]))
        except IOError as e:
            ui.on_error_data(e)
Ejemplo n.º 22
0
    def __init__(self, id, title='', vocab_id=None, container=None):
        # ZCatalog no longer cares about vocabularies
        # so the vocab_id argument is ignored (Casey)

        if container is not None:
            self=self.__of__(container)
        self.id=id
        self.title=title

        # vocabulary and vocab_id are left for backwards
        # compatibility only, they are not used anymore
        self.vocabulary = None
        self.vocab_id = ''

        self.threshold = 10000
        self._v_total = 0

        self._catalog = Catalog()
Ejemplo n.º 23
0
def testmod():
    import doctest
    global testEntry, testCatalog, testToHtml, testArchiveToHtml

    urn = 'urn:x-internet-archive:bookserver:catalog'
    testCatalog = Catalog(title='Internet Archive OPDS', urn=urn)
    testLink = Link(url='http://archive.org/download/itemid.pdf',
                    type='application/pdf',
                    rel='http://opds-spec.org/acquisition/buying')
    catalogLink = Link(url='/providers/IA', type=Link.opds)
    testEntry = Entry(
        {
            'urn': 'x-internet-archive:item:itemid',
            'title': u'test item',
            'updated': '2009-01-01T00:00:00Z',
            'date': '1977-06-17T00:00:55Z',
            'summary': '<p>Fantastic book.</p>',
        },
        links=[testLink])

    start = 0
    numFound = 2
    numRows = 1
    urlBase = '/alpha/a/'
    testNavigation = Navigation.initWithBaseUrl(start, numRows, numFound,
                                                urlBase)
    testCatalog.addNavigation(testNavigation)

    osDescription = 'http://bookserver.archive.org/catalog/opensearch.xml'
    testSearch = OpenSearch(osDescription)
    testCatalog.addOpenSearch(testSearch)

    testCatalog.addEntry(testEntry)
    testToHtml = CatalogToHtml(testCatalog)

    testArchiveToHtml = ArchiveCatalogToHtml(testCatalog)

    doctest.testmod()
Ejemplo n.º 24
0
    def __init__(self, name, location, age, aadhar_id):
        '''
        Constructs all the necessary attributes for the Book object
        ...

        Parameters
        ----------
        name : str
            Name of the user
        location : str
            Resedential city of the User
        age: int
            Age of the User
        aadhar_id: str
            Address proof of the user
        catalog: instance of class Catalog

        '''
        self.name = name
        self.location = location
        self.age = age
        self.aadhar_id = aadhar_id
        self.catalog = Catalog.instance()
 def addBook(self, title, author, publication_date):
     Catalog.add_book(title, author, publication_date)
 def extendDates(self,book_item, ext_days):
     Catalog.extendDates(book_item, ext_days)
 def view_issued_books(self):
     Catalog.view_issued_bookitems(self)
 def removeBookItem(self, rem_bookitem):
     Catalog.remove_book_item(rem_bookitem)
 def removeBook(self, rem_book):
     Catalog.remove_book(rem_book)
 def addBookItem(self, title, isbn, rack):
     Catalog.add_book_item(title, isbn, rack)
Ejemplo n.º 31
0
from Book import Book
from Catalog import Catalog
from User import Member, Librarian

catalog = Catalog()


#reference to Librarian class object
librarian = Librarian("Awantik","Bangalore",34,'asljlkj22','zeke101') 
#details of librarian
print (librarian)
# adding a book by librarian
b2 =librarian.addBook("This is Going to Hurt: Secret Diaries of a Junior Doctor","Adam Key",'2017', 302,catalog)
#adding details
librarian.addBookItem(b2,'234c','l203',catalog)

#displaying all the books till now added
librarian.displayAddedBook(catalog)

#library remove book
librarian.removeBook('Shoe Dog',catalog)


librarian.addBookItem(b2,'235c','1204',catalog)

librarian.removeBookItemFromCatalog(catalog,"This is Going to Hurt: Secret Diaries of a Junior Doctor",'235c')
Ejemplo n.º 32
0
class ZCatalog(Folder, Persistent, Implicit):
    __implements__ = IZCatalog

    """ZCatalog object

    A ZCatalog contains arbirary index like references to Zope
    objects.  ZCatalog's can index either 'Field' values of object, or
    'Text' values.

    ZCatalog does not store references to the objects themselves, but
    rather to a unique identifier that defines how to get to the
    object.  In Zope, this unique idenfier is the object's relative
    path to the ZCatalog (since two Zope object's cannot have the same
    URL, this is an excellent unique qualifier in Zope).

    Most of the dirty work is done in the _catalog object, which is an
    instance of the Catalog class.  An interesting feature of this
    class is that it is not Zope specific.  You can use it in any
    Python program to catalog objects.

    """

    meta_type = "ZCatalog"
    icon='misc_/ZCatalog/ZCatalog.gif'

    manage_options = (
        {'label': 'Contents',           # TAB: Contents
         'action': 'manage_main',
         'help': ('OFSP','ObjectManager_Contents.stx')},
        {'label': 'Catalog',            # TAB: Cataloged Objects
         'action': 'manage_catalogView',
         'help':('ZCatalog','ZCatalog_Cataloged-Objects.stx')},
        {'label': 'Properties',         # TAB: Properties
         'action': 'manage_propertiesForm',
         'help': ('OFSP','Properties.stx')},
        {'label': 'Indexes',            # TAB: Indexes
         'action': 'manage_catalogIndexes',
         'help': ('ZCatalog','ZCatalog_Indexes.stx')},
        {'label': 'Metadata',           # TAB: Metadata
         'action': 'manage_catalogSchema',
         'help':('ZCatalog','ZCatalog_MetaData-Table.stx')},
        {'label': 'Find Objects',       # TAB: Find Objects
         'action': 'manage_catalogFind',
         'help':('ZCatalog','ZCatalog_Find-Items-to-ZCatalog.stx')},
        {'label': 'Advanced',           # TAB: Advanced
         'action': 'manage_catalogAdvanced',
         'help':('ZCatalog','ZCatalog_Advanced.stx')},
        {'label': 'Undo',               # TAB: Undo
         'action': 'manage_UndoForm',
         'help': ('OFSP','Undo.stx')},
        {'label': 'Security',           # TAB: Security
         'action': 'manage_access',
         'help': ('OFSP','Security.stx')},
        {'label': 'Ownership',          # TAB: Ownership
         'action': 'manage_owner',
         'help': ('OFSP','Ownership.stx'),}
        )

    __ac_permissions__=(

        (manage_zcatalog_entries,
         ['manage_catalogObject', 'manage_uncatalogObject',
          'catalog_object', 'uncatalog_object', 'refreshCatalog',

          'manage_catalogView', 'manage_catalogFind',
          'manage_catalogSchema', 'manage_catalogIndexes',
          'manage_catalogAdvanced', 'manage_objectInformation',

          'manage_catalogReindex', 'manage_catalogFoundItems',
          'manage_catalogClear', 'manage_addColumn', 'manage_delColumn',
          'manage_addIndex', 'manage_delIndex', 'manage_clearIndex',
          'manage_reindexIndex', 'manage_main', 'availableSplitters',

          # these two are deprecated:
          'manage_delColumns', 'manage_deleteIndex'
          ],
         ['Manager']),

        (search_zcatalog,
         ['searchResults', '__call__', 'uniqueValuesFor',
          'getpath', 'schema', 'indexes', 'index_objects', 
          'all_meta_types', 'valid_roles', 'resolve_url',
          'getobject'],
         ['Anonymous', 'Manager']),
         
        (manage_zcatalog_indexes, 
         ['getIndexObjects'], 
         ['Manager']),
        )


    manage_catalogAddRowForm = DTMLFile('dtml/catalogAddRowForm', globals())
    manage_catalogView = DTMLFile('dtml/catalogView',globals())
    manage_catalogFind = DTMLFile('dtml/catalogFind',globals())
    manage_catalogSchema = DTMLFile('dtml/catalogSchema', globals())
    manage_catalogIndexes = DTMLFile('dtml/catalogIndexes', globals())
    manage_catalogAdvanced = DTMLFile('dtml/catalogAdvanced', globals())
    manage_objectInformation = DTMLFile('dtml/catalogObjectInformation',
                                        globals())

    Indexes = ZCatalogIndexes()

    threshold=10000
    _v_total=0
    _v_transaction = None

    def __init__(self, id, title='', vocab_id=None, container=None):
        # ZCatalog no longer cares about vocabularies
        # so the vocab_id argument is ignored (Casey)

        if container is not None:
            self=self.__of__(container)
        self.id=id
        self.title=title

        # vocabulary and vocab_id are left for backwards
        # compatibility only, they are not used anymore
        self.vocabulary = None
        self.vocab_id = ''

        self.threshold = 10000
        self._v_total = 0

        self._catalog = Catalog()

    def __len__(self):
        return len(self._catalog)


    # getVocabulary method is no longer supported
    # def getVocabulary(self):
    #   """ more ack! """
    #   return getattr(self, self.vocab_id)


    def manage_edit(self, RESPONSE, URL1, threshold=1000, REQUEST=None):
        """ edit the catalog """
        if type(threshold) is not type(1):
            threshold=int(threshold)
        self.threshold = threshold

        RESPONSE.redirect(
            URL1 + '/manage_main?manage_tabs_message=Catalog%20Changed')


    def manage_subbingToggle(self, REQUEST, RESPONSE, URL1):
        """ toggle subtransactions """
        if self.threshold:
            self.threshold = None
        else:
            self.threshold = 10000

        RESPONSE.redirect(
            URL1 +
            '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Changed')

    def manage_catalogObject(self, REQUEST, RESPONSE, URL1, urls=None):
        """ index Zope object(s) that 'urls' point to """
        if urls:
            if isinstance(urls, types.StringType):
                urls=(urls,)

            for url in urls:
                obj = self.resolve_path(url)
                if not obj:
                    obj = self.resolve_url(url, REQUEST)
                if obj is not None:
                    self.catalog_object(obj, url)

        RESPONSE.redirect(
            URL1 +
            '/manage_catalogView?manage_tabs_message=Object%20Cataloged')


    def manage_uncatalogObject(self, REQUEST, RESPONSE, URL1, urls=None):
        """ removes Zope object(s) 'urls' from catalog """

        if urls:
            if isinstance(urls, types.StringType):
                urls=(urls,)

            for url in urls:
                self.uncatalog_object(url)

        RESPONSE.redirect(
            URL1 +
            '/manage_catalogView?manage_tabs_message=Object%20Uncataloged')


    def manage_catalogReindex(self, REQUEST, RESPONSE, URL1):
        """ clear the catalog, then re-index everything """

        elapse = time.time()
        c_elapse = time.clock()

        self.refreshCatalog(clear=1)

        elapse = time.time() - elapse
        c_elapse = time.clock() - c_elapse

        RESPONSE.redirect(
            URL1 +
            '/manage_catalogAdvanced?manage_tabs_message=' +
            urllib.quote('Catalog Updated \n'
                         'Total time: %s\n'
                         'Total CPU time: %s' % (`elapse`, `c_elapse`)))


    def refreshCatalog(self, clear=0):
        """ re-index everything we can find """

        cat = self._catalog
        paths = cat.paths.values()
        if clear:
            paths = tuple(paths)
            cat.clear()

        for p in paths:
            obj = self.resolve_path(p)
            if not obj:
                obj = self.resolve_url(p, self.REQUEST)
            if obj is not None:
                self.catalog_object(obj, p)

    def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None):
        """ clears the whole enchilada """
        self._catalog.clear()

        if REQUEST and RESPONSE:
            RESPONSE.redirect(
              URL1 +
              '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared')


    def manage_catalogFoundItems(self, REQUEST, RESPONSE, URL2, URL1,
                                 obj_metatypes=None,
                                 obj_ids=None, obj_searchterm=None,
                                 obj_expr=None, obj_mtime=None,
                                 obj_mspec=None, obj_roles=None,
                                 obj_permission=None):

        """ Find object according to search criteria and Catalog them
        """

        elapse = time.time()
        c_elapse = time.clock()

        words = 0
        obj = REQUEST.PARENTS[1]
        path = '/'.join(obj.getPhysicalPath())


        results = self.ZopeFindAndApply(obj,
                                        obj_metatypes=obj_metatypes,
                                        obj_ids=obj_ids,
                                        obj_searchterm=obj_searchterm,
                                        obj_expr=obj_expr,
                                        obj_mtime=obj_mtime,
                                        obj_mspec=obj_mspec,
                                        obj_permission=obj_permission,
                                        obj_roles=obj_roles,
                                        search_sub=1,
                                        REQUEST=REQUEST,
                                        apply_func=self.catalog_object,
                                        apply_path=path)

        elapse = time.time() - elapse
        c_elapse = time.clock() - c_elapse

        RESPONSE.redirect(
            URL1 +
            '/manage_catalogView?manage_tabs_message=' +
            urllib.quote('Catalog Updated\n'
                         'Total time: %s\n'
                         'Total CPU time: %s'
                         % (`elapse`, `c_elapse`))
            )


    def manage_addColumn(self, name, REQUEST=None, RESPONSE=None, URL1=None):
        """ add a column """
        self.addColumn(name)

        if REQUEST and RESPONSE:
            RESPONSE.redirect(
                URL1 +
                '/manage_catalogSchema?manage_tabs_message=Column%20Added')


    def manage_delColumns(self, names, REQUEST=None, RESPONSE=None, URL1=None):
        """ Deprecated method. Use manage_delColumn instead. """
        # log a deprecation warning
        import warnings
        warnings.warn(
            "The manage_delColumns method of ZCatalog is deprecated"
            "since Zope 2.4.2.\n"
            "This method is only kept for backwards compatibility "
            "for a while\n"
            "and will go away in a future release.\n"
            "\n"
            "Please use instead the manage_delColumn method.\n"
            ,DeprecationWarning)

        self.manage_delColumn(names, REQUEST=REQUEST, RESPONSE=RESPONSE,
                              URL1=URL1)


    def manage_delColumn(self, names, REQUEST=None, RESPONSE=None, URL1=None):
        """ delete a column or some columns """
        if isinstance(names, types.StringType):
            names = (names,)

        for name in names:
            self.delColumn(name)

        if REQUEST and RESPONSE:
            RESPONSE.redirect(
                URL1 +
                '/manage_catalogSchema?manage_tabs_message=Column%20Deleted')


    def manage_addIndex(self, name, type, extra=None,
                        REQUEST=None, RESPONSE=None, URL1=None):
        """add an index """
        self.addIndex(name, type,extra)

        if REQUEST and RESPONSE:
            RESPONSE.redirect(
                URL1 +
                '/manage_catalogIndexes?manage_tabs_message=Index%20Added')


    def manage_deleteIndex(self, ids=None, REQUEST=None, RESPONSE=None,
        URL1=None):
        """ Deprecated method. Use manage_delIndex instead. """
        # log a deprecation warning
        import warnings
        warnings.warn(
            "The manage_deleteIndex method of ZCatalog is deprecated"
            "since Zope 2.4.2.\n"
            "This method is only kept for backwards compatibility for a "
            "while\n"
            "and will go away in a future release.\n"
            "\n"
            "Please use instead the manage_delIndex method.\n"
            ,DeprecationWarning)

        self.manage_delIndex(ids=ids, REQUEST=REQUEST, RESPONSE=RESPONSE,
                             URL1=URL1)


    def manage_delIndex(self, ids=None, REQUEST=None, RESPONSE=None,
        URL1=None):
        """ delete an index or some indexes """
        if not ids:
            return MessageDialog(title='No items specified',
                message='No items were specified!',
                action = "./manage_catalogIndexes",)

        if isinstance(ids, types.StringType):
            ids = (ids,)

        for name in ids:
            self.delIndex(name)

        if REQUEST and RESPONSE:
            RESPONSE.redirect(
                URL1 +
                '/manage_catalogIndexes?manage_tabs_message=Index%20Deleted')


    def manage_clearIndex(self, ids=None, REQUEST=None, RESPONSE=None,
        URL1=None):
        """ clear an index or some indexes """
        if not ids:
            return MessageDialog(title='No items specified',
                message='No items were specified!',
                action = "./manage_catalogIndexes",)

        if isinstance(ids, types.StringType):
            ids = (ids,)

        for name in ids:
            self.clearIndex(name)

        if REQUEST and RESPONSE:
            RESPONSE.redirect(
                URL1 +
                '/manage_catalogIndexes?manage_tabs_message=Index%20Cleared')


    def reindexIndex(self, name, REQUEST):
        paths = self._catalog.uids.keys()

        for p in paths:
            obj = self.resolve_path(p)
            if not obj:
                obj = self.resolve_url(p, REQUEST)
            if obj is not None:
                self.catalog_object(obj, p, idxs=[name])


    def manage_reindexIndex(self, ids=None, REQUEST=None, RESPONSE=None,
                            URL1=None):
        """Reindex indexe(s) from a ZCatalog"""
        if not ids:
            return MessageDialog(title='No items specified',
                message='No items were specified!',
                action = "./manage_catalogIndexes",)

        if isinstance(ids, types.StringType):
            ids = (ids,)

        for name in ids:
            self.reindexIndex(name, REQUEST)

        if REQUEST and RESPONSE:
            RESPONSE.redirect(
                URL1 +
                '/manage_catalogIndexes'
                '?manage_tabs_message=Reindexing%20Performed')


    def availableSplitters(self):
        """ splitter we can add """
        return Splitter.availableSplitters


    def catalog_object(self, obj, uid=None, idxs=[]):
        """ wrapper around catalog """

        if uid is None:
            try: uid = obj.getPhysicalPath
            except AttributeError:
                raise CatalogError(
                    "A cataloged object must support the 'getPhysicalPath' "
                    "method if no unique id is provided when cataloging"
                    )
            else: uid='/'.join(uid())
        elif not isinstance(uid,types.StringType):
            raise CatalogError('The object unique id must be a string.')

        self._catalog.catalogObject(obj, uid, None,idxs)
        # None passed in to catalogObject as third argument indicates
        # that we shouldn't try to commit subtransactions within any
        # indexing code.  We throw away the result of the call to
        # catalogObject (which is a word count), because it's
        # worthless to us here.

        if self.threshold is not None:
            # figure out whether or not to commit a subtransaction.
            t = id(get_transaction())
            if t != self._v_transaction:
                self._v_total = 0
            self._v_transaction = t
            self._v_total = self._v_total + 1
            # increment the _v_total counter for this thread only and get
            # a reference to the current transaction.
            # the _v_total counter is zeroed if we notice that we're in
            # a different transaction than the last one that came by.
            # self.threshold represents the number of times that
            # catalog_object needs to be called in order for the catalog
            # to commit a subtransaction.  The semantics here mean that
            # we should commit a subtransaction if our threshhold is
            # exceeded within the boundaries of the current transaction.
            if self._v_total > self.threshold:
                get_transaction().commit(1)
                self._p_jar.cacheGC()
                self._v_total = 0

    def uncatalog_object(self, uid):
        """Wrapper around catalog """
        self._catalog.uncatalogObject(uid)

    def uniqueValuesFor(self, name):
        """Return the unique values for a given FieldIndex """
        return self._catalog.uniqueValuesFor(name)

    def getpath(self, rid):
        """Return the path to a cataloged object given a 'data_record_id_'
        """
        return self._catalog.paths[rid]

    def getrid(self, path, default=None):
        """Return 'data_record_id_' the to a cataloged object given a 'path'
        """
        return self._catalog.uids.get(path, default)

    def getobject(self, rid, REQUEST=None):
        """Return a cataloged object given a 'data_record_id_'
        """
        obj = self.aq_parent.unrestrictedTraverse(self.getpath(rid))
        if not obj:
            if REQUEST is None:
                REQUEST=self.REQUEST
            obj = self.resolve_url(self.getpath(rid), REQUEST)
        return obj

    def getMetadataForUID(self, uid):
        """return the correct metadata given the uid, usually the path"""
        rid = self._catalog.uids[uid]
        return self._catalog.getMetadataForRID(rid)

    def getIndexDataForUID(self, uid):
        """return the current index contents given the uid, usually the path"""
        rid = self._catalog.uids[uid]
        return self._catalog.getIndexDataForRID(rid)

    def getMetadataForRID(self, rid):
        """return the correct metadata for the cataloged record id"""
        return self._catalog.getMetadataForRID(int(rid))

    def getIndexDataForRID(self, rid):
        """return the current index contents for the specific rid"""
        return self._catalog.getIndexDataForRID(rid)

    def schema(self):
        return self._catalog.schema.keys()

    def indexes(self):
        return self._catalog.indexes.keys()

    def index_objects(self):
        # This method returns unwrapped indexes!
        # You should probably use getIndexObjects instead
        return self._catalog.indexes.values()

    def getIndexObjects(self):
        # Return a list of wrapped(!) indexes
        getIndex = self._catalog.getIndex
        return [getIndex(name) for name in self.indexes()]

    def _searchable_arguments(self):
        r = {}
        n={'optional':1}
        for name in self._catalog.indexes.keys():
            r[name]=n
        return r

    def _searchable_result_columns(self):
        r = []
        for name in self._catalog.schema.keys():
            i = {}
            i['name'] = name
            i['type'] = 's'
            i['parser'] = str
            i['width'] = 8
            r.append(i)
        r.append({'name': 'data_record_id_',
                  'type': 's',
                  'parser': str,
                  'width': 8})
        return r

    def searchResults(self, REQUEST=None, used=None, **kw):
        """Search the catalog according to the ZTables search interface.

        Search terms can be passed in the REQUEST or as keyword
        arguments.
        """

        return self._catalog.searchResults(REQUEST, used, **kw)

    __call__=searchResults

## this stuff is so the find machinery works

    meta_types=() # Sub-object types that are specific to this object

    # Dont need this anymore -- we inherit from object manager
    #def all_meta_types(self):
    #    pmt=()
    #    if hasattr(self, '_product_meta_types'): pmt=self._product_meta_types
    #    elif hasattr(self, 'aq_acquire'):
    #        try: pmt=self.aq_acquire('_product_meta_types')
    #        except AttributeError:  pass
    #    return self.meta_types+Products.meta_types+pmt

    def valid_roles(self):
        "Return list of valid roles"
        obj=self
        dict={}
        dup =dict.has_key
        x=0
        while x < 100:
            if hasattr(obj, '__ac_roles__'):
                roles=obj.__ac_roles__
                for role in roles:
                    if not dup(role):
                        dict[role]=1
            if not hasattr(obj, 'aq_parent'):
                break
            obj=obj.aq_parent
            x=x+1
        roles=dict.keys()
        roles.sort()
        return roles

    def ZopeFindAndApply(self, obj, obj_ids=None, obj_metatypes=None,
                         obj_searchterm=None, obj_expr=None,
                         obj_mtime=None, obj_mspec=None,
                         obj_permission=None, obj_roles=None,
                         search_sub=0,
                         REQUEST=None, result=None, pre='',
                         apply_func=None, apply_path=''):
        """Zope Find interface and apply

        This is a *great* hack.  Zope find just doesn't do what we
        need here; the ability to apply a method to all the objects
        *as they're found* and the need to pass the object's path into
        that method.

        """

        if result is None:
            result=[]

            if obj_metatypes and 'all' in obj_metatypes:
                obj_metatypes=None

            if obj_mtime and type(obj_mtime)==type('s'):
                obj_mtime=DateTime(obj_mtime).timeTime()

            if obj_permission:
                obj_permission=p_name(obj_permission)

            if obj_roles and type(obj_roles) is type('s'):
                obj_roles=[obj_roles]

            if obj_expr:
                # Setup expr machinations
                md=td()
                obj_expr=(Eval(obj_expr), md, md._push, md._pop)

        base=obj
        if hasattr(obj, 'aq_base'):
            base=obj.aq_base

        if not hasattr(base, 'objectItems'):
            return result
        try:    items=obj.objectItems()
        except: return result

        try: add_result=result.append
        except:
            raise AttributeError, `result`

        for id, ob in items:
            if pre: p="%s/%s" % (pre, id)
            else:   p=id

            dflag=0
            if hasattr(ob, '_p_changed') and (ob._p_changed == None):
                dflag=1

            if hasattr(ob, 'aq_base'):
                bs=ob.aq_base
            else: bs=ob

            if (
                (not obj_ids or absattr(bs.id) in obj_ids)
                and
                (not obj_metatypes or (hasattr(bs, 'meta_type') and
                 bs.meta_type in obj_metatypes))
                and
                (not obj_searchterm or
                 (hasattr(ob, 'PrincipiaSearchSource') and
                  ob.PrincipiaSearchSource().find(obj_searchterm) >= 0
                  ))
                and
                (not obj_expr or expr_match(ob, obj_expr))
                and
                (not obj_mtime or mtime_match(ob, obj_mtime, obj_mspec))
                and
                ( (not obj_permission or not obj_roles) or \
                   role_match(ob, obj_permission, obj_roles)
                )
                ):
                if apply_func:
                    apply_func(ob, (apply_path+'/'+p))
                else:
                    add_result((p, ob))
                    dflag=0

            if search_sub and hasattr(bs, 'objectItems'):
                self.ZopeFindAndApply(ob, obj_ids, obj_metatypes,
                                      obj_searchterm, obj_expr,
                                      obj_mtime, obj_mspec,
                                      obj_permission, obj_roles,
                                      search_sub,
                                      REQUEST, result, p,
                                      apply_func, apply_path)
            if dflag: ob._p_deactivate()

        return result

    def resolve_url(self, path, REQUEST):
        """
        Attempt to resolve a url into an object in the Zope
        namespace. The url may be absolute or a catalog path
        style url. If no object is found, None is returned.
        No exceptions are raised.
        """
        script=REQUEST.script
        if path.find(script) != 0:
            path='%s/%s' % (script, path)
        try: return REQUEST.resolve_url(path)
        except: pass

    def resolve_path(self, path):
        """
        Attempt to resolve a url into an object in the Zope
        namespace. The url may be absolute or a catalog path
        style url. If no object is found, None is returned.
        No exceptions are raised.
        """
        try: return self.unrestrictedTraverse(path)
        except: pass

    def manage_normalize_paths(self, REQUEST):
        """Ensure that all catalog paths are full physical paths

        This should only be used with ZCatalogs in which all paths can
        be resolved with unrestrictedTraverse."""

        paths = self._catalog.paths
        uids = self._catalog.uids
        unchanged = 0
        fixed = []
        removed = []

        for path, rid in uids.items():
            ob = None
            if path[:1] == '/':
                ob = self.resolve_url(path[1:],REQUEST)
            if ob is None:
                ob = self.resolve_url(path, REQUEST)
                if ob is None:
                    removed.append(path)
                    continue
            ppath = '/'.join(ob.getPhysicalPath())
            if path != ppath:
                fixed.append((path, ppath))
            else:
                unchanged = unchanged + 1

        for path, ppath in fixed:
            rid = uids[path]
            del uids[path]
            paths[rid] = ppath
            uids[ppath] = rid
        for path in removed:
            self.uncatalog_object(path)

        return MessageDialog(title='Done Normalizing Paths',
          message='%s paths normalized, %s paths removed, and '
                  '%s unchanged.' % (len(fixed), len(removed), unchanged),
          action='./manage_main')

    def manage_convertBTrees(self, threshold=200):
        """Convert the catalog's data structures to use BTrees package"""
        assert type(threshold) is type(0)
        tt=time.time()
        ct=time.clock()
        self._catalog._convertBTrees(threshold)
        tt=time.time()-tt
        ct=time.clock()-ct
        return 'Finished conversion in %s seconds (%s cpu)' % (tt, ct)


    def manage_convertIndex(self, ids, REQUEST=None, RESPONSE=None, URL1=None):
        """convert old-style indexes to new-style indexes"""

        from Products.PluginIndexes.KeywordIndex import KeywordIndex
        from Products.PluginIndexes.FieldIndex import FieldIndex
        from Products.PluginIndexes.TextIndex import TextIndex

        converted = []
        for id in ids:
            idx = self.Indexes[id]

            iface = getattr(idx,'__implements__',None)
            if iface is None:

                mt = idx.meta_type

                converted.append(id)
                self.delIndex(id)

                if mt in ('Field Index','Keyword Index'):
                    self.addIndex(id,mt.replace(' ',''))
                elif mt == 'Text Index':
                    # TODO: Lexicon handling to be added
                    self.addIndex(id,'TextIndex')

        if converted:
            RESPONSE.redirect(
                URL1 +
                '/manage_main?manage_tabs_message=Indexes%20converted')
        else:
            RESPONSE.redirect(
                URL1 +
                '/manage_main?'
                'manage_tabs_message='
                'No%20indexes%20found%20to%20be%20converted')


    #
    # Indexing methods
    #

    def addIndex(self, name, type,extra=None):
        # Convert the type by finding an appropriate product which supports
        # this interface by that name.  Bleah

        products = ObjectManager.all_meta_types(self, interfaces=(
            PluggableIndexInterface,))

        p = None

        for prod in products:
            if prod['name'] == type:
                p = prod
                break

        if p is None:
            raise ValueError, "Index of type %s not found" % type

        base = p['instance']

        if base is None:
            raise ValueError, "Index type %s does not support addIndex" % type

        # This code is somewhat lame but every index type has its own
        # function signature *sigh* and there is no common way to pass
        # additional parameters to the constructor. The suggested way
        # for new index types is to use an "extra" record.

        if 'extra' in base.__init__.func_code.co_varnames:
            index = base(name, extra=extra, caller=aq_base(self))
        else:
            index = base(name, aq_base(self))

        self._catalog.addIndex(name,index)


    def delIndex(self, name ):
        self._catalog.delIndex(name)

    def clearIndex(self, name):
        self._catalog.getIndex(name).clear()


    def addColumn(self, name, default_value=None):
        return self._catalog.addColumn(name, default_value)

    def delColumn(self, name):
        return self._catalog.delColumn(name)
Ejemplo n.º 33
0
from Catalog import Catalog
from User import Member

catalog = Catalog()

b = catalog.addBook('Shoe Dog', 'Phil Knight', '2015', 312)
catalog.addBookItem(b, '123hg', 'H1B2')
catalog.addBookItem(b, '124hg', 'H1B4')
catalog.addBookItem(b, '125hg', 'H1B5')

b = catalog.addBook('Moonwalking with Einstien', 'J Foer', '2017', 318)
catalog.addBookItem(b, '463hg', 'K1B2')

b = catalog.addBook('Pax', 'Sara Pennypacker', '2017', 288)
catalog.addBookItem(b, '554jk', 'M24A')
catalog.addBookItem(b, '556jk', 'M25A')
catalog.addBookItem(b, '557jk', 'M26A')

catalog.displayAllBooks()

catalog.removeBook('Pax')

catalog.displayAllBooks()

catalog.removeBookItem('Shoe Dog', '124hg')
catalog.displayAllBooks()

b = catalog.searchByName('Shoe Dog')
print(b)

b = catalog.searchByAuthor('J Foer')
Ejemplo n.º 34
0
import ephem
from itertools import count
from ephem import hours, degrees, Equatorial, Ecliptic
from Orbit import Orbit
from Catalog import Catalog, DateTime, TimeDelta, Point
from DECamField import DECamField
from DECamExposure import DECamExposure
from ccdBounds import *
from MPCRecord import MPCRecord
import easyaccess as ea

sidereal_year = 365.256363
sidereal_rate = ephem.degrees(2*np.pi/sidereal_year)


fields = Catalog('fields.csv', name=str, centerra=float, centerdec=float, opposition=float, visitspath=str, orderedby='name')
fields.add_property('center', lambda pt: Equatorial(hours(pt.centerra), degrees(pt.centerdec)))
#fields.add_property('visits', lambda pt: Catalog(pt.visitspath, nite=int, date=float, dlon=float, dlat=float, vlon=float, vlat=float))
fields.refactor('opposition', DateTime)
#for field in fields: field.visits.refactor('date', DateTime)

def _exp_contains(self, ra1, dec1): return DECamField(self.ra, self.dec).contains(ra1, dec1)
def _exp_ellipse(self): return DECamField(self.ra, self.dec).ellipse()

exposures = Catalog('exposures.csv', expnum=int, date=float, ra=float, dec=float, exptime=float, nite=int, band=str, tag=str, object=str,
    fwhm_asec=float, t_eff=float, ellipticity=float, skybrightness=float, accepted=str, analyst=str, analyst_comment=str, lastchanged_time=str)
exposures.refactor('date', lambda date: ephem.date(date))
exposures.refactor('ra', lambda ra: hours(ra))
exposures.refactor('dec', lambda dec: degrees(dec))
exposures.add_function('contains', _exp_contains)
exposures.add_function('ellipse', _exp_contains)