def get_metadata_archive(): ''' It creates a file (ARCHIVE_NAME) with all the information Returns the file ''' ensure_dir(TMP_DIR) file_list = [ {'name': 'kanux_version.txt', 'contents': get_version()}, {'name': 'kanux_stamp.txt', 'contents': get_stamp()}, {'name': 'process.txt', 'contents': get_processes()}, {'name': 'packages.txt', 'contents': get_packages()}, {'name': 'dmesg.txt', 'contents': get_dmesg()}, {'name': 'syslog.txt', 'contents': get_syslog()}, {'name': 'cmdline.txt', 'contents': read_file_contents('/boot/cmdline.txt')}, {'name': 'config.txt', 'contents': read_file_contents('/boot/config.txt')}, {'name': 'wifi-info.txt', 'contents': get_wifi_info()}, {'name': 'usbdevices.txt', 'contents': get_usb_devices()}, # TODO: Remove raw logs when json ones become stable {'name': 'app-logs.txt', 'contents': get_app_logs_raw()}, {'name': 'app-logs-json.txt', 'contents': get_app_logs_json()}, {'name': 'hdmi-info.txt', 'contents': get_hdmi_info()}, {'name': 'edid.dat', 'contents': get_edid()}, {'name': 'screen-log.txt', 'contents': get_screen_log()}, {'name': 'xorg-log.txt', 'contents': get_xorg_log()}, {'name': 'cpu-info.txt', 'contents': get_cpu_info()}, {'name': 'lsof.txt', 'contents': get_lsof()}, {'name': 'content-objects.txt', 'contents': get_co_list()} ] # Include the screenshot if it exists if os.path.isfile(SCREENSHOT_PATH): file_list.append({ 'name': SCREENSHOT_NAME, 'contents': read_file_contents(SCREENSHOT_PATH) }) # Collect all coredumps, for applications that terminated unexpectedly for f in os.listdir('/var/tmp/'): if f.startswith('core-'): file_list.append({ 'name': f, 'contents': read_file_contents(os.path.join('/var/tmp', f)) }) # create files for each non empty metadata info for file in file_list: if file['contents']: write_file_contents(TMP_DIR + file['name'], file['contents']) # archive all the metadata files # need to change dir to avoid tar subdirectories current_directory = os.getcwd() os.chdir(TMP_DIR) run_cmd("tar -zcvf {} *".format(ARCHIVE_NAME)) # open the file and return it archive = open(ARCHIVE_NAME, 'rb') # restore the current working directory os.chdir(current_directory) return archive
def get_metadata_archive(): ''' It creates a file (ARCHIVE_NAME) with all the information Returns the file ''' ensure_dir(TMP_DIR) file_list = [ {'name': 'kanux_version.txt', 'contents': get_version()}, {'name': 'process.txt', 'contents': get_processes()}, {'name': 'packages.txt', 'contents': get_packages()}, {'name': 'dmesg.txt', 'contents': get_dmesg()}, {'name': 'syslog.txt', 'contents': get_syslog()}, {'name': 'cmdline.txt', 'contents': read_file_contents('/boot/cmdline.txt')}, {'name': 'config.txt', 'contents': read_file_contents('/boot/config.txt')}, {'name': 'wifi-info.txt', 'contents': get_wifi_info()}, {'name': 'usbdevices.txt', 'contents': get_usb_devices()}, # TODO: Remove raw logs when json ones become stable {'name': 'app-logs.txt', 'contents': get_app_logs_raw()}, {'name': 'app-logs-json.txt', 'contents': get_app_logs_json()}, {'name': 'hdmi-info.txt', 'contents': get_hdmi_info()}, {'name': 'xorg-log.txt', 'contents': get_xorg_log()}, {'name': 'cpu-info.txt', 'contents': get_cpu_info()}, {'name': 'lsof.txt', 'contents': get_lsof()}, {'name': 'content-objects.txt', 'contents': get_co_list()} ] # Include the screenshot if it exists if os.path.isfile(SCREENSHOT_PATH): file_list.append({ 'name': SCREENSHOT_NAME, 'contents': read_file_contents(SCREENSHOT_PATH) }) # create files for each non empty metadata info for file in file_list: if file['contents']: write_file_contents(TMP_DIR + file['name'], file['contents']) # Collect all coredumps, for applications that terminated unexpectedly for f in os.listdir('/var/tmp/'): if f.startswith('core-'): file_list.append({ 'name': f, 'contents': read_file_contents(os.path.join('/var/tmp', f)) }) # archive all the metadata files # need to change dir to avoid tar subdirectories current_directory = os.getcwd() os.chdir(TMP_DIR) run_cmd("tar -zcvf {} *".format(ARCHIVE_NAME)) # open the file and return it archive = open(ARCHIVE_NAME, 'rb') # restore the current working directory os.chdir(current_directory) return archive
def get_stamp(): """Get the initial starting version of the OS. Returns: str: The contents of the kanux_stamp file """ return read_file_contents('/boot/kanux_stamp') or ''
def edit_hosts_file(path, new_hostname): try: hosts = read_file_contents(path) hosts += '\n' + hosts_mod_comment + '\n' hosts += '127.0.0.1\t{}\n'.format(new_hostname) write_file_contents(path, hosts) except: logger.error("exception while changing change {}".format(path))
def is_locale_valid(locale): """ The supported file list (UTF-8) entries take the form <language>_<REGION>[.\s]UTF-8(\sUTF-8)? """ return re.search(standard_locale_to_genfile_entry(locale), read_file_contents(SUPPORTED_LIST_FILE))
def get_edid(): file_path = os.path.join(TMP_DIR, 'edid.dat') cmd = "tvservice -d {}".format(file_path) run_cmd(cmd) try: dat = read_file_contents(file_path) delete_file(file_path) return dat except: return "EMPTY"
def get_edid(): file_path = TMP_DIR + 'edid.dat' cmd = "tvservice -d {}".format(file_path) run_cmd(cmd) try: dat = read_file_contents(file_path) delete_file(file_path) return dat except: return "EMPTY"
def save_kano_version(): """Saves a dict of os-version: time values, to keep track of the users update process""" updates = load_app_state_variable('kano-tracker', 'versions') if not updates: updates = dict() version_now = read_file_contents('/etc/kanux_version') if not version_now: return version_now = version_now.replace('.', '_') time_now = datetime.datetime.utcnow().isoformat() updates[version_now] = time_now save_app_state_variable('kano-tracker', 'versions', updates)
def set_parental_enabled(setting, _password): logger.debug('set_parental_enabled: {}'.format(setting)) # turning on if setting: logger.debug('enabling') logger.debug('setting password') write_file_contents(password_file, encrypt_password(_password)) logger.debug('making the file root read-only') os.chmod(password_file, 0400) logger.debug('enabling parental controls') set_parental_level(get_parental_level()) msg = N_("Parental lock enabled!") logger.debug(msg) return True, _(msg) # turning off else: # password matches if read_file_contents(password_file) == encrypt_password(_password): logger.debug('password accepted, disabling') logger.debug('clearing password') os.remove(password_file) logger.debug('disabling parental controls') set_parental_level(-1) msg = N_("Parental lock disabled!") logger.debug(msg) return True, _(msg) # password doesn't match else: msg = N_("Password doesn't match\nleaving parental lock enabled!") logger.debug(msg) return False, _(msg)
def set_parental_enabled(setting, _password): logger.debug('set_parental_enabled: {}'.format(setting)) # turning on if setting: logger.debug('enabling') logger.debug('setting password') write_file_contents(password_file, encrypt_password(_password)) logger.debug('making the file root read-only') os.chmod(password_file, 0400) logger.debug('enabling parental controls') set_parental_level(get_parental_level()) msg = "Parental lock enabled!" logger.debug(msg) return True, msg # turning off else: # password matches if read_file_contents(password_file) == encrypt_password(_password): logger.debug('password accepted, disabling') logger.debug('clearing password') os.remove(password_file) logger.debug('disabling parental controls') set_parental_level(-1) msg = "Parental lock disabled!" logger.debug(msg) return True, msg # password doesn't match else: msg = "Password doesn't match\nleaving parental lock enabled!" logger.debug(msg) return False, msg
def __init__(self, win): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) image = Gtk.Image.new_from_file(media + "/Graphics/about-screen.png") version_number, os_name = get_current_version() os_variant = read_file_contents('/etc/kanux_version_variant') version_align = self.create_align( "Kano OS: {name} v{version}".format(name=os_name, version=version_number), 'about_version' ) if os_variant: variant_align = self.create_align( "{variant}".format(variant=os_variant), 'about_version' ) space_align = self.create_align( _("Disk space used: {used}B / {total}B").format(**get_space_available()) ) try: celsius = u"{:.1f}\N{DEGREE SIGN}C".format(get_temperature()) except ValueError: celsius = "?" temperature_align = self.create_align( _(u"Temperature: {celsius}").format(celsius=celsius) ) model_align = self.create_align( _("Model: {model}").format(model=get_model_name()) ) terms_and_conditions = OrangeButton(_("Terms and conditions")) terms_and_conditions.connect( 'button_release_event', self.show_terms_and_conditions ) credits_button = OrangeButton(_("Meet the team")) credits_button.connect( 'button_release_event', self.show_credits ) self.kano_button = KanoButton(_("BACK")) self.kano_button.pack_and_align() hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) hbox.pack_start(terms_and_conditions, False, False, 4) hbox.pack_start(credits_button, False, False, 4) hbutton_container = Gtk.Alignment( xalign=0.5, xscale=0, yalign=0, yscale=0 ) hbutton_container.add(hbox) image.set_margin_top(10) self.pack_start(image, False, False, 10) self.pack_start(version_align, False, False, 2) if os_variant: self.pack_start(variant_align, False, False, 2) self.pack_start(space_align, False, False, 1) self.pack_start(temperature_align, False, False, 1) self.pack_start(model_align, False, False, 1) self.pack_start(hbutton_container, False, False, 3) self.pack_start(self.kano_button.align, False, False, 10) self.kano_button.connect('button-release-event', self.win.go_to_home) self.kano_button.connect('key-release-event', self.win.go_to_home) # Refresh window self.win.show_all()
def get_metadata_archive(title='', desc=''): ''' It creates a file (ARCHIVE_NAME) with all the information Returns the file ''' ensure_dir(TMP_DIR) file_list = [ { 'name': 'metadata.json', 'contents': json.dumps({ 'title': title, 'description': desc }) }, { 'name': 'kanux_version.txt', 'contents': get_version() }, { 'name': 'kanux_stamp.txt', 'contents': get_stamp() }, { 'name': 'process.txt', 'contents': get_processes() }, { 'name': 'process-tree.txt', 'contents': get_process_tree() }, { 'name': 'packages.txt', 'contents': get_packages() }, { 'name': 'dmesg.txt', 'contents': get_dmesg() }, { 'name': 'syslog.txt', 'contents': get_syslog() }, { 'name': 'cmdline.txt', 'contents': read_file_contents('/boot/cmdline.txt') }, { 'name': 'config.txt', 'contents': read_file_contents('/boot/config.txt') }, { 'name': 'wifi-info.txt', 'contents': get_wifi_info() }, { 'name': 'usbdevices.txt', 'contents': get_usb_devices() }, # TODO: Remove raw logs when json ones become stable { 'name': 'app-logs.txt', 'contents': get_app_logs_raw() }, { 'name': 'app-logs-json.txt', 'contents': get_app_logs_json() }, { 'name': 'hdmi-info.txt', 'contents': get_hdmi_info() }, { 'name': 'edid.dat', 'contents': get_edid() }, { 'name': 'screen-log.txt', 'contents': get_screen_log() }, { 'name': 'xorg-log.txt', 'contents': get_xorg_log() }, { 'name': 'cpu-info.txt', 'contents': get_cpu_info() }, { 'name': 'mem-stats.txt', 'contents': get_mem_stats() }, { 'name': 'lsof.txt', 'contents': get_lsof() }, { 'name': 'content-objects.txt', 'contents': get_co_list() }, { 'name': 'disk-space.txt', 'contents': get_disk_space() }, { 'name': 'lsblk.txt', 'contents': get_lsblk() }, { 'name': 'sources-list.txt', 'contents': get_sources_list() }, ] file_list += get_install_logs() # Include the screenshot if it exists if os.path.isfile(SCREENSHOT_PATH): file_list.append({ 'name': SCREENSHOT_NAME, 'contents': read_file_contents(SCREENSHOT_PATH) }) # Collect all coredumps, for applications that terminated unexpectedly for f in os.listdir('/var/tmp/'): if f.startswith('core-'): file_list.append({ 'name': f, 'contents': read_file_contents(os.path.join('/var/tmp', f)) }) # create files for each non empty metadata info for file in file_list: if file['contents']: write_file_contents(os.path.join(TMP_DIR, file['name']), file['contents']) # archive all the metadata files import tarfile with tarfile.open(ARCHIVE_PATH, mode='w') as archive: for f in os.listdir(TMP_DIR): archive.add(os.path.join(TMP_DIR, f), arcname=f) # open the file and return it archive = open(ARCHIVE_PATH, 'rb') return archive
def authenticate_parental_password(passwd): return read_file_contents(password_file) == encrypt_password(passwd)
chown_path(tracker_token_file) # Make sure that the events file exist try: f = open(tracker_events_file, 'a') except IOError as e: logger.error('Error opening tracker events file {}'.format(e)) else: f.close() if 'SUDO_USER' in os.environ: chown_path(tracker_events_file) return token OS_VERSION = str(read_file_contents('/etc/kanux_version')) CPU_ID = str(get_cpu_id()) TOKEN = load_token() def get_session_file_path(name, pid): return "{}/{}-{}.json".format(tracker_dir, pid, name) def session_start(name, pid=None): if not pid: pid = os.getpid() pid = int(pid) data = { "pid": pid,
def __init__(self, win): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) image = Gtk.Image.new_from_file(media + "/Graphics/about-screen.png") version_number, os_name = get_current_version() os_variant = read_file_contents('/etc/kanux_version_variant') cpu_id = get_cpu_id() version_align = self.create_align( "Kano OS: {name} v{version}".format(name=os_name, version=version_number), 'about_version' ) if os_variant: variant_align = self.create_align( "{variant}".format(variant=os_variant), 'about_version' ) space_align = self.create_align( _("Disk space used: {used}B / {total}B").format(**get_space_available()) ) try: celsius = u"{:.1f}\N{DEGREE SIGN}C".format(get_temperature()) except ValueError: celsius = "?" temperature_align = self.create_align( _(u"Temperature: {celsius}").format(celsius=celsius) ) model_align = self.create_align( _("Model: {model}").format(model=get_model_name()) ) cpu_id_align = self.create_align( _("CPU ID: {id}").format(id=cpu_id) ) terms_and_conditions = OrangeButton(_("Terms and conditions")) terms_and_conditions.connect( 'button_release_event', self.show_terms_and_conditions ) credits_button = OrangeButton(_("Meet the team")) credits_button.connect( 'button_release_event', self.show_credits ) self.kano_button = KanoButton(_("BACK")) self.kano_button.pack_and_align() hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) hbox.pack_start(terms_and_conditions, False, False, 4) hbox.pack_start(credits_button, False, False, 4) hbutton_container = Gtk.Alignment( xalign=0.5, xscale=0, yalign=0, yscale=0 ) hbutton_container.add(hbox) image.set_margin_top(10) self.pack_start(image, False, False, 10) self.pack_start(version_align, False, False, 2) if os_variant: self.pack_start(variant_align, False, False, 2) self.pack_start(space_align, False, False, 1) self.pack_start(temperature_align, False, False, 1) self.pack_start(model_align, False, False, 1) self.pack_start(cpu_id_align, False, False, 1) self.pack_start(hbutton_container, False, False, 3) self.pack_start(self.kano_button.align, False, False, 10) self.kano_button.connect('button-release-event', self.win.go_to_home) self.kano_button.connect('key-release-event', self.win.go_to_home) # Refresh window self.win.show_all()
def get_metadata_archive(title='', desc=''): ''' It creates a file (ARCHIVE_NAME) with all the information Returns the file ''' ensure_dir(TMP_DIR) file_list = [ { 'name': 'metadata.json', 'contents': json.dumps({'title': title, 'description': desc}) }, {'name': 'kanux_version.txt', 'contents': get_version()}, {'name': 'kanux_stamp.txt', 'contents': get_stamp()}, {'name': 'process.txt', 'contents': get_processes()}, {'name': 'process-tree.txt', 'contents': get_process_tree()}, {'name': 'packages.txt', 'contents': get_packages()}, {'name': 'dmesg.txt', 'contents': get_dmesg()}, {'name': 'syslog.txt', 'contents': get_syslog()}, { 'name': 'cmdline.txt', 'contents': read_file_contents('/boot/cmdline.txt') }, { 'name': 'config.txt', 'contents': read_file_contents('/boot/config.txt') }, {'name': 'wifi-info.txt', 'contents': get_wifi_info()}, {'name': 'usbdevices.txt', 'contents': get_usb_devices()}, # TODO: Remove raw logs when json ones become stable {'name': 'app-logs.txt', 'contents': get_app_logs_raw()}, {'name': 'app-logs-json.txt', 'contents': get_app_logs_json()}, {'name': 'hdmi-info.txt', 'contents': get_hdmi_info()}, {'name': 'edid.dat', 'contents': get_edid()}, {'name': 'screen-log.txt', 'contents': get_screen_log()}, {'name': 'xorg-log.txt', 'contents': get_xorg_log()}, {'name': 'cpu-info.txt', 'contents': get_cpu_info()}, {'name': 'mem-stats.txt', 'contents': get_mem_stats()}, {'name': 'lsof.txt', 'contents': get_lsof()}, {'name': 'content-objects.txt', 'contents': get_co_list()}, {'name': 'disk-space.txt', 'contents': get_disk_space()}, {'name': 'lsblk.txt', 'contents': get_lsblk()}, {'name': 'sources-list.txt', 'contents': get_sources_list()}, ] file_list += get_install_logs() # Include the screenshot if it exists if os.path.isfile(SCREENSHOT_PATH): file_list.append({ 'name': SCREENSHOT_NAME, 'contents': read_file_contents(SCREENSHOT_PATH) }) # Collect all coredumps, for applications that terminated unexpectedly for f in os.listdir('/var/tmp/'): if f.startswith('core-'): file_list.append({ 'name': f, 'contents': read_file_contents(os.path.join('/var/tmp', f)) }) # create files for each non empty metadata info for file in file_list: if file['contents']: write_file_contents( os.path.join(TMP_DIR, file['name']), file['contents'] ) # archive all the metadata files import tarfile with tarfile.open(ARCHIVE_PATH, mode='w') as archive: for f in os.listdir(TMP_DIR): archive.add(os.path.join(TMP_DIR, f), arcname=f) # open the file and return it archive = open(ARCHIVE_PATH, 'rb') return archive