def state(): response.content_type = 'application/json' #TODO: Complete! return json.dumps({"is-recording" : context.get_recorder().is_recording(), "hostname" : context.get_conf().get_hostname(), "net" : context.get_ocservice().net if context.get_ocservice() else None, "recorder-status" : str(context.get_recorder().status), "current-profile" : context.get_conf().get_current_profile().name, "current-mediapackage" : context.get_recorder().current_mediapackage.getIdentifier() if context.get_recorder().current_mediapackage else None })
def init(): global minfree, logger, repo, ocservice, dispatcher conf = context.get_conf() dispatcher = context.get_dispatcher() repo = context.get_repository() logger = context.get_logger() ocservice = context.get_ocservice() minfree = None try: minfree = int(conf.get('checkspace', 'minfreespace')) except Exception as exc: raise Exception("Wrong parameter minfreespace: {}".format(exc)) if minfree: logger.info("Parameter 'minfreespace' set to {} GB".format(minfree)) dispatcher.connect('timer-nightly', check_space) dispatcher.connect('recorder-status', check_space_status) oninit = conf.get('checkspace', 'checkoninit') if oninit in ["True", "true"]: check_space(None) else: raise Exception("Parameter minfreespace not configured")
def get_series(): repo = context.get_repository() ocservice = context.get_ocservice() # Import the 'series' section as a dictionary series_conf = context.get_conf().get_section('series') # Init 'queries' dictionary queries = {'startPage': 0, 'count': RESULTS_PER_PAGE} # Filter out keys that do not refer to a certain series property # Also, substitute any placeholder(s) used to filter the series # TODO Currently the only placeholder is {user} for key in list(series_conf.keys()): if key not in DISALLOWED_QUERIES: try: queries[key] = series_conf[key].format(**MAPPINGS) except KeyError: # If the placeholder does not exist, log the issue but ignore it # TODO Log the exception pass try: series_list = [] check_default = True while True: if not ocservice.net: break series_json = json.loads(ocservice.client.getseries(**queries)) for catalog in series_json['catalogs']: try: series_list.append(parse_json_series(catalog)) except KeyError: # Ignore ill-formated series pass if len(series_list) >= int(series_json['totalCount']): # Check the default series is present, otherwise query for it if 'default' in series_conf and check_default and series_conf[ 'default'] not in dict(series_list): check_default = False queries = {"seriesId": series_conf['default']} else: break else: queries['startPage'] += 1 repo.save_attach('series.json', json.dumps(series_list)) except (ValueError, IOError, RuntimeError, AttributeError): #TODO Log the exception try: series_list = json.load(repo.get_attach('series.json')) except (ValueError, IOError): #TODO Log the exception series_list = [] return series_list
def get_series(): repo = context.get_repository() ocservice = context.get_ocservice() # Import the 'series' section as a dictionary series_conf = context.get_conf().get_section('series') # Init 'queries' dictionary queries = {'startPage': 0, 'count': RESULTS_PER_PAGE} # Filter out keys that do not refer to a certain series property # Also, substitute any placeholder(s) used to filter the series # TODO Currently the only placeholder is {user} for key in series_conf.keys(): if key not in DISALLOWED_QUERIES: try: queries[key] = series_conf[key].format(**MAPPINGS) except KeyError: # If the placeholder does not exist, log the issue but ignore it # TODO Log the exception pass try: series_list = [] check_default = True while True: if not ocservice.net: break series_json = json.loads(ocservice.client.getseries(**queries)) for catalog in series_json['catalogs']: try: series_list.append(parse_json_series(catalog)) except KeyError: # Ignore ill-formated series pass if len(series_list) >= int(series_json['totalCount']): # Check the default series is present, otherwise query for it if 'default' in series_conf and check_default and series_conf['default'] not in dict(series_list): check_default = False queries = { "seriesId": series_conf['default'] } else: break else: queries['startPage'] += 1 repo.save_attach('series.json', json.dumps(series_list)) except (ValueError, IOError, RuntimeError, AttributeError): #TODO Log the exception try: series_list = json.load(repo.get_attach('series.json')) except (ValueError, IOError): #TODO Log the exception series_list = [] return series_list
def init(): global logger, repo, ocservice, dispatcher conf = context.get_conf() dispatcher = context.get_dispatcher() repo = context.get_repository() logger = context.get_logger() ocservice = context.get_ocservice() logger.info("Logging process memory use") dispatcher.connect('timer-long', check_mem)
def load_modules(self): self.window = context.get_mainwindow() # Load plugins after loading the main window (fixes a problem with the plugin 'nocursor') plugins.init() # Recorder self.recorder = RecorderClassUI() self.insert_page(self.recorder, 'REC') if 'scheduler' in self.modules: self.scheduler = context.get_scheduler() if 'ocservice' in self.modules: self.ocservice = context.get_ocservice() if 'media_manager' in self.modules: self.dispatcher.connect('action-view-change', self.change_mode) # Distribution self.distribution = DistribUI() self.insert_page(self.distribution, 'DIS') # Media Manager self.listing = ListingClassUI() self.insert_page(self.listing, 'MMA') if 'player' in self.modules: self.player = PlayerClassUI() self.insert_page(self.player, 'PLA') self.window.start() # Set home page homepage = self.conf.get_choice('basic', 'homepage', ['rec', 'pla', 'mma', 'dis'], 'mma').upper() if not 'media_manager' in self.modules or PAGES[homepage] not in PAGES_LOADED: logger.info("Set REC as home page (default value), modules loaded: {}".format(self.modules)) self.window.set_current_page(PAGES['REC']) self.recorder.block() else: logger.info("Set {} as home page, modules loaded: {}".format(homepage, self.modules)) self.window.set_current_page(PAGES[homepage]) # Notify home page setting by issuing a 'view-changed' signal self.dispatcher.emit('view-changed', None, self.window.get_current_page()) context.get_heartbeat().init_timer() self.dispatcher.emit("init")
def on_rec(button): global dispatcher, recorder, recorder_ui, metadata dispatcher.emit("action-audio-disable-msg") mp = None if not recorder.current_mediapackage: mp = recorder.create_mp() if not mp: mp = recorder.current_mediapackage # Add default metadata to the MP mp.metadata_episode.update(metadata) ocservice = context.get_ocservice() series_list = [] if ocservice: series_list = ocservice.series # Check the series try: del (mp.metadata_episode['isPartOf']) mp.metadata_series = utils_series.filterSeriesbyId( series_list, metadata['isPartOf'])['list'] except (TypeError, KeyError): # There was no series specified, so no change was needed pass arguments = { 'package': mp, #'series_list': series_list, 'title': _("New Recording"), 'subtitle': _("New Recording"), 'ok_label': _("Start"), } if len(series_list) <= 1: arguments['empty_series_label'] = None popup = MetadataClass(**arguments) if popup.return_value == -8: recorder_ui.on_rec(button=None) dispatcher.emit("action-audio-enable-msg")
def on_rec(button): global dispatcher, recorder, recorder_ui, metadata dispatcher.emit("action-audio-disable-msg") mp = None if not recorder.current_mediapackage: mp = recorder.create_mp() if not mp: mp = recorder.current_mediapackage # Add default metadata to the MP mp.metadata_episode.update(metadata) ocservice = context.get_ocservice() series_list= [] if ocservice: series_list = ocservice.series # Check the series try: del(mp.metadata_episode['isPartOf']) mp.metadata_series = utils_series.filterSeriesbyId(series_list, metadata['isPartOf'])['list'] except (TypeError, KeyError): # There was no series specified, so no change was needed pass arguments = { 'package': mp, #'series_list': series_list, 'title': _("New Recording"), 'subtitle': _("New Recording"), 'ok_label': _("Start"), } if len(series_list) <= 1: arguments['empty_series_label'] = None popup = MetadataClass(**arguments) if popup.return_value == -8: recorder_ui.on_rec(button=None) dispatcher.emit("action-audio-enable-msg")
def __init__(self, package=None, parent=None, title=_("Edit Metadata"), subtitle=_("Edit Metadata"), ok_label=_("Save"), ko_label=_("Cancel"), empty_series_label=NO_SERIES): """ """ parent = context.get_mainwindow() size = parent.get_size() self.par = parent altura = size[1] anchura = size[0] k1 = anchura / 1920.0 k2 = altura / 1080.0 self.wprop = k1 self.hprop = k2 ocservice = context.get_ocservice() self.series_list = [] if ocservice: self.series_list = context.get_ocservice().series self.empty_series_label = empty_series_label gui = Gtk.Builder() gui.add_from_file(get_ui_path('metadata.glade')) dialog = gui.get_object("metadatadialog") # Set up the dialog's label gui.get_object("title").set_text(subtitle) # Set up the button text gui.get_object("slabel").set_label(ok_label) gui.get_object("clabel").set_label(ko_label) dialog.set_property("width-request", int(anchura / 2.2)) #dialog.set_type_hint(Gdk.WindowTypeHint.TOOLBAR) #dialog.set_modal(True) #dialog.set_keep_above(False) #NEW HEADER strip = Header(size=size, title=title) dialog.vbox.pack_start(strip, True, True, 0) dialog.vbox.reorder_child(strip, 0) if parent != None: # FIXME: The keyboard plugin uses Ubuntu Onboard. # https://bugs.launchpad.net/onboard/+bug/1627819 # There is a bug with this plugin where the "dock to edges" # option does not work with the "force to top" one, causing # Onboard to appear behind when Galicaster is on fullscreen. # THIS affects #321. A better solution should be implemented. from galicaster import plugins if not parent.is_fullscreen or 'galicaster.plugins.keyboard' not in plugins.loaded: dialog.set_transient_for(parent.get_toplevel()) dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS) dialog_style_context = dialog.get_style_context() window_classes = parent.get_style_context().list_classes() for style_class in window_classes: dialog_style_context.add_class(style_class) table = gui.get_object('infobox') dialog.vbox.set_child_packing(table, True, True, int(self.hprop * 25), Gtk.PackType.END) title = gui.get_object('title') talign = gui.get_object('table_align') title.hide() # Get "blocked" and "mandatory" parameters blocked = set() mandatory = set() try: for term in context.get_conf().get('metadata', 'blocked').split(): try: blocked.add(EQUIV[term]) except KeyError: blocked.add(term) except (KeyError, AttributeError): # 'blocked' was not defined in configuration pass try: for term in context.get_conf().get('metadata', 'mandatory').split(): try: mandatory.add(EQUIV[term]) except KeyError: mandatory.add(term) except (KeyError, AttributeError): # 'mandatory' was not defined in configuration pass self.mandatory = {} ok_button = gui.get_object("savebutton") self.fill_metadata(table, package, ok_button, blocked, mandatory) self.check_mandatory(None, ok_button, check_all=True) talign.set_padding(int(self.hprop * 25), int(self.hprop * 10), int(self.hprop * 25), int(self.hprop * 25)) dialog.vbox.set_child_packing(dialog.action_area, True, True, int(self.hprop * 25), Gtk.PackType.END) dialog.show_all() parent.get_style_context().add_class('shaded') self.return_value = dialog.run() if self.return_value == -8: self.update_metadata(table, package) parent.get_style_context().remove_class('shaded') dialog.destroy()