def main(): try: lib = library.Library(db='games.db') except FileNotFoundError: lib = library.Library(base=os.path.join('..', 'games')) if sys.argv[1] == 'help': Help() elif sys.argv[1] == 'list': if len(sys.argv) > 2: pred = lambda x: x.Platform() == sys.argv[2] else: pred = lambda x: True for game in lib.List(pred=pred): print('%-30s %-20s %s' % (game.Name(), game.ID(), game.Path())) elif sys.argv[1] == 'prepare': game = lib.Game(sys.argv[2]) game.Prepare() elif sys.argv[1] == 'finalize': game = lib.Game(sys.argv[2]) game.Finalize() elif sys.argv[1] == 'rebuild': lib.Persist('games.db')
def run(self): ''' This is a thread to not block the main service thread. ''' try: if 'default' in Emby.client: window('emby_online', clear=True) Emby().close() if self.service['library'] is not None: self.service['library'].stop_client() self.service['library'] = None if self.close: raise Exception("terminate default server thread") if self.retry and self.service['monitor'].waitForAbort( self.retry) or not self.service.running: raise Exception("abort default server thread") self.service['connect'].register() setup.Setup() self.service['mode'] = settings('useDirectPaths') if self.service['library'] is None: self.service['library'] = library.Library(self.service) except Exception as error: LOG.error( error ) # we don't really case, event will retrigger if need be. self.service.server_thread.remove(self)
def main(): (n_days, bookValues, tup_libraries) = parse() libraries = [] for idx in range(len(tup_libraries)): (a, b, c) = tup_libraries[idx] libraries.append(library.Library(a, b, c, idx)) day = 0 days_till_sign_up = 0 signed_up_libs = [] next_lib = None while day < n_days: for lib in signed_up_libs: lib.sendBooks(bookValues) if days_till_sign_up == 0: if next_lib: signed_up_libs.append(next_lib) next_lib.sendBooks(bookValues) days_till_sign_up, next_lib = choose_library( libraries, n_days - day, bookValues) day += 1 days_till_sign_up -= 1 # output print(str(len(signed_up_libs))) for lib in signed_up_libs: print(str(lib.idx), str(len(lib.booksSent))) line = "" for book in lib.booksSent: line += str(book) + " " print(line[:-1])
def test_library_eroot_generated(): lib = library.Library() smith = library.Writer() lib.writers.append(smith) assert smith.eContainer() is lib assert smith.eRoot() is lib assert library.Library.eClass.eRoot() is library.eClass
class Test(unittest.TestCase): books = [] obj = l.Library() def test_add_book(self): book = self.obj.add_book('Akshada') self.books.append('Akshada') self.assertEqual(book, self.books) print(book) print(self.books) def test_display_book(self): b = self.obj.display_books() if self.books: self.assertEqual(b, self.books) else: self.assertEqual(b, False) def test_lend_book(self): # Request for a book flag = self.obj.lend_book("Akshada") if 'Akshada' in self.books: self.books.remove('Akshada') self.assertEqual(flag, True) else: print('Book is not in library')
def setUp(self): grid_object.GridObject.clear_objects() self.__library = library.Library("test_library") self.__grid = C_Grid(10, 10) self.__make_test_library()
def parse(input_file_path): with open(input_file_path, "r") as input_file: books_count, libraries_count, days = ( int(x) for x in input_file.readline().split(' ')) # print books_count, libraries_count, days books = [ book.Book(book_id, score) for (book_id, score) in enumerate(input_file.readline().split(' ')) ] # for b in books: # print b.id, b.score libraries_data_lines = input_file.readlines() # print libraries_data_lines libraries = [] for lib_id in range(libraries_count): number_of_books, signup_time, scanning_throughput = ( int(x) for x in libraries_data_lines[2 * lib_id].split(' ')) # print number_of_books, signup_time, scanning_throughput books_ids = [ int(x) for x in libraries_data_lines[2 * lib_id + 1].split(' ') ] libraries.append( library.Library(lib_id, signup_time, scanning_throughput, books_ids)) # for lib in libraries: # print lib.id, lib.signup_time, lib.scanning_throughput, lib.books_ids return task_setting.TaskSetting(books_count, libraries_count, days, libraries, books)
def __init__(self, project): self._project = project self._csv = project.csv self._runlist = project.runlist self._cal_file = project.path.runlist_file self._library = library.Library(project.path.library_file_ref, project.csv)
def __init__(self, name): self.name = name self.lib = library.Library('00') self.lib.LoadDefaultLibrary() self.key_array = self.lib.string_array self.index_array = self.lib.index_array self.library_array = self.lib.library_array self.file_array = self.lib.file_array
def test_library_econtents_generated(): smith = library.Writer() book = library.Book() lib = library.Library() lib.writers.append(smith) lib.books.append(book) assert smith in lib.eContents assert book in lib.eContents
def main(): assert len(sys.argv) == 2 server_ip = get_ip_from_dns(dns_address=('172.20.4.159', 8080)) print("server ip: ", server_ip) server_adress = (server_ip, 9090) library.Library(server_adress, sys.argv[1].lower()) library.mainloop()
def test_notification_static_unset(): library = lib.Library() o = LastNotification(library) library.name = 'SuperLib' library.name = None notif = o.notification assert notif.kind is Kind.UNSET assert notif.old == 'SuperLib' assert notif.feature is lib.Library.name
def test_notification_static_set(): library = lib.Library() o = LastNotification(library) library.name = 'SuperLib' notif = o.notification assert notif.kind is Kind.SET assert notif.new == 'SuperLib' assert notif.old is None assert notif.feature is lib.Library.name
def LoadLibraryByFingerByFile(self, finger): lib_index = self.library_array.index(finger)+8 if self.library_array[lib_index] == '0': pass elif self.lib.name == self.library_array[lib_index]: pass else: self.lib = library.Library(self.library_array[lib_index]) self.lib.LoadFromFile(self.file_array[lib_index]) self.LoadLibraryArrays() pass
def setUp(self): self.lib_fn = r'v:\workspace\PersistentStorage\src\lib.shelve' self.lib = library.Library(self.lib_fn) self.fixture_author1 = library.Author('Octavia', 'Estelle', 'Butler') self.fixture_book1 = library.Book('0807083100', 'Kindred', [self.fixture_author1]) self.fixture_author2 = library.Author('Robert', 'Anson', 'Heinlein') self.fixture_book2 = library.Book('0441790348', 'Stranger in a Strange Land', [self.fixture_author2]) self.lib.add(self.fixture_book1) self.lib.add(self.fixture_book2)
def setUp(self): self.lib_fn = r'/Users/chris/Documents/dev/oreilly/python/python2/lib' \ r'.shelve' self.lib = library.Library(self.lib_fn) self.fixture_author1 = library.Author('Octavia', 'Estelle', 'Butler') self.fixture_book1 = library.Book('0807083100', 'Kindred', [self.fixture_author1]) self.fixture_author2 = library.Author('Robert', 'Anson', 'Heinlein') self.fixture_book2 = library.Book('0441790348', 'Stranger in a ' 'Strange Land', [self.fixture_author2]) self.lib.add(self.fixture_book1) self.lib.add(self.fixture_book2)
def run(self): starttime = datetime.now().strftime('%Y%m%d-%H%M') if self.album: alb = albums.Albums(self.out, starttime, self.catalogdir, self.credential, self.bucketname, self.bucketprefix) alb.run() if self.library: lib = library.Library(self.out, starttime, self.catalogdir, self.credential, self.bucketname, self.bucketprefix) lib.run()
def setUp(self): self.lib_fn = "/Users/Fadel/Dropbox/python/Code/Python2/05-PersistentStorage/LibraryExample/lib.shelve" self.lib = library.Library(self.lib_fn) self.fixture_author1 = library.Author("Octavia", "Estelle", "Butler") self.fixture_book1 = library.Book("0807083100", "Kindred", [self.fixture_author1]) self.fixture_author2 = library.Author("Robert‰a", "Anson", "Heinlein") self.fixture_book2 = library.Book("0441709348", "Stranger in a Strange Land", [self.fixture_author2]) self.lib.add(self.fixture_book1) self.lib.add(self.fixture_book2)
def start_library_system(file_name): '''Load the library from disk and start menu of actions.''' print("Loading library in file {}.".format(file_name)) library = l.Library.load_from_file(file_name) if not library: library_label = input("Enter New Library Name: ") library = l.Library(library_label) print("Your Current Library Layout:") library.describe(False) print() while True: if run_menu(library, file_name): break
def __init__(self, config): """ This class implements the data-template-based trend detection technique presented by Nikolov (http://dspace.mit.edu/bitstream/handle/1721.1/85399/870304955.pdf) The auxiliary module "library" (or equivalent code) is required. """ # set up basic member variables self.current_count = None self.total_series = [] self.trend_weight = None self.non_trend_weight = None self.SMALL_NUMBER = 0.001 # manage everything related to distance measurements self.set_up_distance_measures(config) # config handling if "series_length" in config: self.series_length = int(config["series_length"]) else: self.series_length = 50 if "reference_length" in config: self.reference_length = int(config["reference_length"]) else: self.reference_length = 210 if "lambda" in config: self.Lambda = float(config["lambda"]) else: self.Lambda = 1 #if "logger" in config: # self.logger = config["logger"] #else: # self.logger = logging.getLogger("default_template_logger") #self.logger = logr import library if "library_file_name" in config: self.library = pickle.load(open(config["library_file_name"],'rb')) else: self.library = library.Library(config={}) self.config = config
def __init__(self): self.display = library.Printer() self.library = library.Library() fahrenheit = int(raw_input("Enter the degrees in Fahrenheit.")) celsius = self.library.fahrenheit_to_celsius(fahrenheit) self.display.fahrenheit = fahrenheit self.display.celsius = celsius milliliters = int( raw_input("Enter the volume of the cup in Milliliters")) gallons = self.library.milliliters_to_gallons(milliliters) self.display.milliliters = milliliters self.display.gallons = gallons self.display.calc()
def create_library(self): self._library = library.Library(self._project.path.library_file_ref, self._project.csv) self.datadict() self.codedict() refineRT = False if self._project.info.auto_RT == 'yes': refineRT = True factor = self._project.info.refine_factor for code in list(self._library.library.keys()): if not code in self._codedict: del self._library.library[code] elif refineRT == True: self._library.library[code]['RT'] = \ stat.median(self._codedict[code]) self._library.library[code]['lim'] /= factor self._codelist = self._library.write_library\ (self._project.path.library_file) return
def __init__(self): self.library = library.Library() now = datetime.datetime.now() adjusted_weekday = now.weekday() adjusted_hour = now.hour + now.minute / constants.MINUTES_IN_HOUR if adjusted_hour < constants.ANIMATED_START_HOUR: adjusted_hour += constants.HOURS_IN_DAY adjusted_weekday = (adjusted_weekday - 1) % constants.DAYS_IN_WEEK print(adjusted_weekday) active_routines = list() if not self.override_routines(): if adjusted_weekday > 3 or True: active_routines = self.library.get_all_routines() else: choice_routines = list() choice_routines.append("line_highlight_routine") choice_routines.append("line_highlight_rainbow_routine") choice_routines.append("red_blocks") choice_routines.append("spurt_routine") choice_routines.append("bricks") choice_routines.append("projector_visuals") choice_routines.append("hues") active_routines.append(random.choice(choice_routines)) self.library.set_active_routines(active_routines) self.routine_queue = queue.Queue() self.transitions_queue = queue.Queue() self.next_transition_timestamp = self.get_next_transition_time() self.previous_routine = None self.current_routine = self.get_next_routine() self.current_transition = None self.start_transition() self.default_frame = np.zeros(shape=(constants.LED_COUNT, 3), dtype=int)
def __init__(self): #declaring attributes from library self.printer = library.Printer() self.library = library.Library() #Lets get some inputs cows = int(raw_input("How many cows would you like on your farm? ")) milk = self.library.produce_milk(cows) chickens = int( raw_input("How many chickens would you like on your farm? ")) eggs = self.library.produce_eggs(chickens) #Lets set some paths for the variables for the printer self.printer.cows = cows self.printer.milk = milk self.printer.chickens = chickens self.printer.eggs = eggs #DIsplay function from library self.printer.display_function()
import RPi.GPIO as GPIO import library import time import os import thread # PINS pin_led = 17 pin_button1 = 26 pin_button2 = 7 pin_light = 12 pin_ldr = 3 # INITILIAZE LIBRARY CLASS l = library.Library(pin_led, pin_button1, pin_button2, pin_light, pin_ldr) def audio(): os.system('mpg123 maag.mp3') #def animation(): #... def maag(): state = 0 #longen is active while state is 0: input = GPIO.input(l.pin_button1) if input is 0: #have to press button to work state = 1 if state is 1: GPIO.output(l.pin_led, True) # LED is on time.sleep(1)
import RPi.GPIO as GPIO import library # PINS pin_led_hart = 17 pin_button1 = 18 pin_button2 = 4 pin_button3 = 7 pin_button4 = 9 pin_led_l1 = 21 pin_led_l2 = 20 pin_led_l3 = 16 # INITILIAZE LIBRARY CLASS l = library.Library(pin_led_hart, pin_button1, pin_button2, pin_button3, pin_button4, pin_led_l1, pin_led_l2, pin_led_l3) GPIO.cleanup()
def onNotification(self, sender, method, data): ''' All notifications are sent via NotifyAll built-in or Kodi. Central hub. ''' if sender.lower() not in ('plugin.video.jellyfin', 'xbmc'): return if sender == 'plugin.video.jellyfin': method = method.split('.')[1] if method not in ('ServerUnreachable', 'ServerShuttingDown', 'UserDataChanged', 'ServerConnect', 'LibraryChanged', 'ServerOnline', 'SyncLibrary', 'RepairLibrary', 'RemoveLibrary', 'SyncLibrarySelection', 'RepairLibrarySelection', 'AddServer', 'Unauthorized', 'UpdateServer', 'UserConfigurationUpdated', 'ServerRestarting', 'RemoveServer', 'AddLibrarySelection', 'RemoveLibrarySelection'): return data = json.loads(data)[0] else: if method not in ('System.OnQuit', 'System.OnSleep', 'System.OnWake'): return data = json.loads(data) LOG.debug("[ %s: %s ] %s", sender, method, json.dumps(data, indent=4)) if method == 'ServerOnline': if data.get('ServerId') is None: window('jellyfin_online.bool', True) self.settings['auth_check'] = True self.warn = True if settings('connectMsg.bool'): users = [ user for user in ( settings('additionalUsers') or "").split(',') if user ] users.insert(0, settings('username')) dialog("notification", heading="{jellyfin}", message="%s %s" % (translate(33000), ", ".join(users)), icon="{jellyfin}", time=1500, sound=False) if self.library_thread is None: self.library_thread = library.Library(self) self.library_thread.start() elif method in ('ServerUnreachable', 'ServerShuttingDown'): if self.warn or data.get('ServerId'): self.warn = data.get('ServerId') is not None dialog("notification", heading="{jellyfin}", message=translate(33146) if data.get('ServerId') is None else translate(33149), icon=xbmcgui.NOTIFICATION_ERROR) if data.get('ServerId') is None: self.stop_default() if self.waitForAbort(120): return self.start_default() elif method == 'Unauthorized': dialog("notification", heading="{jellyfin}", message=translate(33147) if data['ServerId'] is None else translate(33148), icon=xbmcgui.NOTIFICATION_ERROR) if data.get('ServerId') is None and self.settings['auth_check']: self.settings['auth_check'] = False self.stop_default() if self.waitForAbort(5): return self.start_default() elif method == 'ServerRestarting': if data.get('ServerId'): return if settings('restartMsg.bool'): dialog("notification", heading="{jellyfin}", message=translate(33006), icon="{jellyfin}") self.stop_default() if self.waitForAbort(15): return self.start_default() elif method == 'ServerConnect': self.connect.register(data['Id']) xbmc.executebuiltin("Container.Refresh") elif method == 'AddServer': self.connect.setup_manual_server() xbmc.executebuiltin("Container.Refresh") elif method == 'RemoveServer': self.connect.remove_server(data['Id']) xbmc.executebuiltin("Container.Refresh") elif method == 'UpdateServer': dialog("ok", heading="{jellyfin}", line1=translate(33151)) self.connect.setup_manual_server() elif method == 'UserDataChanged' and self.library_thread: if data.get('ServerId') or not window('jellyfin_startup.bool'): return LOG.info("[ UserDataChanged ] %s", data) self.library_thread.userdata(data['UserDataList']) elif method == 'LibraryChanged' and self.library_thread: if data.get('ServerId') or not window('jellyfin_startup.bool'): return LOG.info("[ LibraryChanged ] %s", data) self.library_thread.updated(data['ItemsUpdated'] + data['ItemsAdded']) self.library_thread.removed(data['ItemsRemoved']) elif method == 'System.OnQuit': window('jellyfin_should_stop.bool', True) self.running = False elif method in ('SyncLibrarySelection', 'RepairLibrarySelection', 'AddLibrarySelection', 'RemoveLibrarySelection'): self.library_thread.select_libraries(method) elif method == 'SyncLibrary': if not data.get('Id'): return self.library_thread.add_library(data['Id'], data.get('Update', False)) xbmc.executebuiltin("Container.Refresh") elif method == 'RepairLibrary': if not data.get('Id'): return libraries = data['Id'].split(',') for lib in libraries: if not self.library_thread.remove_library(lib): return self.library_thread.add_library(data['Id']) xbmc.executebuiltin("Container.Refresh") elif method == 'RemoveLibrary': libraries = data['Id'].split(',') for lib in libraries: if not self.library_thread.remove_library(lib): return xbmc.executebuiltin("Container.Refresh") elif method == 'System.OnSleep': LOG.info("-->[ sleep ]") window('jellyfin_should_stop.bool', True) if self.library_thread is not None: self.library_thread.stop_client() self.library_thread = None Jellyfin.close_all() self.monitor.server = [] self.monitor.sleep = True elif method == 'System.OnWake': if not self.monitor.sleep: LOG.warning( "System.OnSleep was never called, skip System.OnWake") return LOG.info("--<[ sleep ]") xbmc.sleep(10000) # Allow network to wake up self.monitor.sleep = False window('jellyfin_should_stop', clear=True) try: self.connect.register() except Exception as error: LOG.exception(error) elif method == 'GUI.OnScreensaverDeactivated': LOG.info("--<[ screensaver ]") xbmc.sleep(5000) if self.library_thread is not None: self.library_thread.fast_sync() elif method == 'UserConfigurationUpdated': if data.get('ServerId') is None: Views().get_views()
import book import student as st import library import teacher library = library.Library() student = st.Student('Arthur') student2 = st.Student('Bim') teacher = teacher.Teacher('Grand') #teacher2 = teacher.Teacher('Master') library.show_books_list() book1 = book.Book('author1', 'pytnonBook1') book2 = book.Book('author1', 'pytnonBook2') book3 = book.Book('author1', 'pytnonBook3') book4 = book.Book('author1', 'pytnonBook4') book5 = book.Book('author1', 'pytnonBook5') book6 = book.Book('author1', 'pytnonBook6') book7 = book.Book('author1', 'pytnonBook7') book8 = book.Book('author1', 'pytnonBook8') book9 = book.Book('author1', 'pytnonBook9') book10 = book.Book('author1', 'pytnonBook10') library.add_book_to_library(book1) library.add_book_to_library(book2) library.add_book_to_library(book3) library.add_book_to_library(book4) library.add_book_to_library(book5) library.add_book_to_library(book6) library.add_book_to_library(book7) library.add_book_to_library(book8)
#! /usr/bin/python import library from query import * import os import time import gc music_database = library.Library() def auto(): '''Tasks to be run automatically each time the program starts up.''' music_database.load() if music_database.empty(): print("\nThere is no library in this directory. Please import songs.") else: num = music_database.size() print("\nLibrary loaded! Contains %d songs.\n\n" % num) music_database.export() menu() def cache_library(): '''Caches and optionally clears currently stored library.''' print("****\n\n") if music_database.empty(): print("Library empty.") else: print("Library will be cached.") print("Do you also want to clear working library? [y/n]") print("(Enter 'm' to return to menu)") clear_ans = raw_input()
#!/usr/bin/env python # coding: utf8 import os import math import requests import json import pickle import re import HTMLParser from BeautifulSoup import BeautifulSoup import xbmcaddon, xbmcgui import library as lib addon = xbmcaddon.Addon() mxdlib = lib.Library() def getAssetClass(asset_class): if asset_class.lower() == 'multiassetbundletvseries': return 'tvshow' elif asset_class.lower() == 'multiassettvseriesseason': return 'tvseason' elif asset_class.lower() == 'assetvideofilm': return 'movie' elif asset_class.lower() == 'assetvideofilmtvseries': return 'tvepisode' elif asset_class.lower() == 'multiassetthemespecial': return 'theme' return None