def replace_polybar( configuration, json_file): prnt.prnt( '-n', 'Replacing your Polybar configuration file') if( fileu.locate_file( configuration['polybar-config'])): prnt.prnt( '-s', 'Located your polybar configuration file') if 'polybar' in json_file: polybar = json_file['polybar'] prnt.prnt( '-s', 'Found you polybar info in the JSON file') rl.replace_line( configuration['polybar-config'], 'background =', 'background = '+polybar['background']) rl.replace_line( configuration['polybar-config'], 'foreground =', 'foreground = '+polybar['foreground']) rl.replace_line( configuration['polybar-config'], 'modules-left', 'modules-left = '+polybar['modules-left']) rl.replace_line( configuration['polybar-config'], 'modules-center', 'modules-center = '+polybar['modules-center']) rl.replace_line( configuration['polybar-config'], 'modules-right', 'modules-right = '+ polybar['modules-right']) rl.replace_line( configuration['polybar-config'], 'label-unfocused-background', 'label-unfocused-background = '+polybar['label-unfocused-background']) rl.replace_line( configuration['polybar-config'], 'label-unfocused-foreground', 'label-unfocused-foreground = '+polybar['label-unfocused-foreground']) rl.replace_line( configuration['polybar-config'], 'label-focused-background', 'label-focused-background = '+polybar['label-focused-background']) rl.replace_line( configuration['polybar-config'], 'label-focused-foreground', 'label-focused-foreground = '+polybar['label-focused-foreground']) rl.replace_line( configuration['polybar-config'], 'label-visible-background', 'label-visible-background = '+polybar['label-visible-background']) rl.replace_line( configuration['polybar-config'], 'label-visible-foreground', 'label-visible-foreground = '+polybar['label-visible-foreground']) rl.replace_line( configuration['polybar-config'], 'label-mode-background', 'label-mode-background = '+polybar['label-mode-background']) rl.replace_line( configuration['polybar-config'], 'label-mode-foreground', 'label-mode-foreground = '+polybar['label-mode-foreground']) rl.replace_line( configuration['polybar-config'], 'format-foreground', 'format-foreground = '+polybar['format-foreground']) rl.replace_line( configuration['polybar-config'], 'format-background', 'format-background = '+polybar['format-background']) rl.replace_line( configuration['polybar-config'], 'label-open-foreground', 'label-open-foreground = '+polybar['label-open-foreground']) rl.replace_line( configuration['polybar-config'], 'label-close-foreground', 'label-close-foreground = '+polybar['label-close-foreground']) rl.replace_line( configuration['polybar-config'], 'label-separator-foreground', 'label-separator-foreground = '+polybar['label-separator-foreground']) rl.replace_line( configuration['polybar-config'], 'format-connected-foreground', 'format-connected-foreground = '+polybar['format-connected-foreground']) rl.replace_line( configuration['polybar-config'], 'format-connected-background', 'format-connected-background = '+polybar['format-connected-background']) rl.replace_line( configuration['polybar-config'], 'format-connected-prefix-foreground', 'format-connected-prefix-foreground = '+polybar['format-connected-prefix-foreground']) rl.replace_line( configuration['polybar-config'], 'ramp-signal-foreground', 'ramp-signal-foreground = '+polybar['ramp-signal-foreground']) else: prnt.prnt( '-f', 'Failed to locate polybar info in the JSON file') else: prnt.prnt( '-f', 'Failed to locate your polybar configuration file')
def load_json( path ): file = '' if( fileu.locate_file(path) ): prnt.prnt( '-s', 'Located the json file') with open( path ) as json_data: file = json.load(json_data) else: prnt.prnt( '-f', 'Failed to locate the json file') exit( 9 ) return file
def install_file(config, install_file, new_file): if (fileu.locate_file(config[install_file])): prnt.prnt('-s', 'Located ' + config[install_file] + 'file!') if (copyfile(new_file, config[install_file])): prnt.prnt('-s', 'Installed the new file successfully!') return True else: prnt.prnt('-f', 'Failed to install the new file!') return False else: prnt.prnt('-f', 'Could not locate ' + config[install_file] + ' file!') return False
def backup_file(config, back_file, destination): if (fileu.locate_file(config[back_file])): prnt.prnt('-s', 'Located your ' + config[back_file] + ' file!') if (copyfile(config[back_file], destination)): prnt.prnt('-s', 'Backed it up successfully!') return True else: prnt.prnt('-f', 'Failed to back it up!') return False else: prnt.prnt('-f', 'Could not locate ' + config[back_file] + ' file!') return False
def install_file(config, install_file, new_file): if (fileu.locate_file(config[install_file])): prnt.prnt('-s', 'Located ' + config[install_file] + 'file!') try: copyfile(new_file, config[install_file]) prnt.prnt('-s', 'Installed the new file successfully!') return True except IOError as error: prnt.prnt('-f', 'Failed to install the new file!') prnt.prnt('-f', 'IOError: {0}'.format(error)) return False else: prnt.prnt('-f', 'Could not locate ' + config[install_file] + ' file!') return False
def backup_file( config, back_file, destination): if(fileu.locate_file(config[back_file])): prnt.prnt( '-s', 'Located your '+config[back_file]+' file!') try: copyfile( config[back_file], destination) prnt.prnt( '-s', 'Backed it up successfully!') return True except IOError as error: prnt.prnt( '-f', 'Failed to back it up!') prnt.prnt( '-f', 'IOError: {0}'.format(error)) return False else: prnt.prnt( '-f', 'Could not locate '+config[back_file]+' file!') return False
def read_config( path ): configuration = {} if( fileu.locate_file( path ) ): prnt.prnt( '-n', 'Located the config file') config_path = open( path, 'r') config = yaml.load_all(config_path) for conf in config: for n, v in conf.items( ): configuration[n] = v else: prnt.prnt( '-f', 'Failed to locate the config file') exit(9) return configuration
def replace_wallpaper( configuration, json_file): prnt.prnt( '-n', 'Replacing wallpaper') if( fileu.locate_file(configuration['nitrogen-config'])): prnt.prnt( '-s', 'Located your nitrogen configuration file') if 'wallpaper' in json_file: wallpaper = json_file['wallpaper'] prnt.prnt( '-s', 'Found the wallpaper info in the JSON file') rl.replace_line( configuration['nitrogen-config'], 'file', 'file= '+configuration['wallpaper-path']+wallpaper) new_file='wallpapers/'+wallpaper try: fileu.copy_file(new_file, configuration['wallpaper-path']+wallpaper) prnt.prnt( '-s', 'Installed the new file successfully!') return True except: prnt.prnt( '-f', 'Failed to install the new file!') return False else: prnt.prnt( '-f', 'Failed to locate your nitrogen configuration file')
def replace_xresources( configuration, json_file): prnt.prnt( '-n', 'Replacing the colors in .Xresources') if( fileu.locate_file(configuration['xresources'])): prnt.prnt( '-s', 'Located your .Xresources file') if 'xresources' in json_file: xresources = json_file['xresources'] prnt.prnt( '-s', 'Found the Xresources info in the JSON file') rl.replace_line( configuration['xresources'], '*background:', '*background: '+xresources['background']) rl.replace_line( configuration['xresources'], '*foreground:', '*foreground: '+xresources['foreground']) rl.replace_line( configuration['xresources'], '*cursorColor:', '*cursorColor: '+xresources['cursorcolor']) for i in range(15): rl.replace_line( configuration['xresources'], '*color'+str(i)+':', '*color'+str(i)+': '+xresources['color'+str(i)]) rl.replace_line( configuration['xresources'], 'rofi.color-window:', 'rofi.color-window: '+xresources['rofi.color-window']) rl.replace_line( configuration['xresources'], 'rofi.color-normal:', 'rofi.color-normal: '+xresources['rofi.color-normal']) rl.replace_line( configuration['xresources'], 'rofi.color-active:', 'rofi.color-active: '+xresources['rofi.color-active']) rl.replace_line( configuration['xresources'], 'rofi.color-urgent:', 'rofi.color-urgent: '+xresources['rofi.color-urgent']) else: prnt.prnt( '-f', 'Failed to locate the Xresources info in the JSON file') else: prnt.prnt( '-f', 'Failed to locate your .Xresources file')
def replace_i3(configuration, json_file): prnt.prnt('-n', 'Replacing the colors in your i3 configuration file') if (fileu.locate_file(configuration['i3-config'])): prnt.prnt('-s', 'Located your i3 configuration file') if 'i3wm' in json_file: i3wm = json_file['i3wm'] prnt.prnt('-s', 'Found the i3wm info in the JSON file') rl.replace_line(configuration['i3-config'], 'client.background', 'client.background ' + i3wm['client.background']) rl.replace_line(configuration['i3-config'], 'client.focused ', 'client.focused ' + i3wm['client.focused']) rl.replace_line(configuration['i3-config'], 'client.unfocused', 'client.unfocused ' + i3wm['client.unfocused']) rl.replace_line( configuration['i3-config'], 'client.focused_inactive', 'client.focused_inactive ' + i3wm['client.focused_inactive']) rl.replace_line(configuration['i3-config'], 'client.urgent', 'client.urgent ' + i3wm['client.urgent']) rl.replace_line(configuration['i3-config'], 'client.placeholder', 'client.placeholder ' + i3wm['client.placeholder']) else: prnt.prnt('-f', 'Failed to locate your i3 configuration file')
def replace_xresources(configuration, json_file): prnt.prnt('-n', 'Replacing the colors in .Xresources') if (fileu.locate_file(configuration['xresources'])): prnt.prnt('-s', 'Located your .Xresources file') if 'xresources' in json_file: xresources = json_file['xresources'] prnt.prnt('-s', 'Found the Xresources info in the JSON file') rl.replace_line(configuration['xresources'], '*background:', '*background: ' + xresources['background']) rl.replace_line(configuration['xresources'], '*foreground:', '*foreground: ' + xresources['foreground']) rl.replace_line(configuration['xresources'], '*cursorColor:', '*cursorColor: ' + xresources['cursorcolor']) for i in range(15): rl.replace_line( configuration['xresources'], '*color' + str(i) + ':', '*color' + str(i) + ': ' + xresources['color' + str(i)]) rl.replace_line( configuration['xresources'], 'rofi.color-window:', 'rofi.color-window: ' + xresources['rofi.color-window']) rl.replace_line( configuration['xresources'], 'rofi.color-normal:', 'rofi.color-normal: ' + xresources['rofi.color-normal']) rl.replace_line( configuration['xresources'], 'rofi.color-active:', 'rofi.color-active: ' + xresources['rofi.color-active']) rl.replace_line( configuration['xresources'], 'rofi.color-urgent:', 'rofi.color-urgent: ' + xresources['rofi.color-urgent']) else: prnt.prnt('-f', 'Failed to locate the Xresources info in the JSON file') else: prnt.prnt('-f', 'Failed to locate your .Xresources file')
def replace_polybar(configuration, json_file): prnt.prnt('-n', 'Replacing your Polybar configuration file') if (fileu.locate_file(configuration['polybar-config'])): prnt.prnt('-s', 'Located your polybar configuration file') if 'polybar' in json_file: polybar = json_file['polybar'] prnt.prnt('-s', 'Found you polybar info in the JSON file') rl.replace_line(configuration['polybar-config'], 'background =', 'background = ' + polybar['background']) rl.replace_line(configuration['polybar-config'], 'foreground =', 'foreground = ' + polybar['foreground']) rl.replace_line(configuration['polybar-config'], 'modules-left', 'modules-left = ' + polybar['modules-left']) rl.replace_line(configuration['polybar-config'], 'modules-center', 'modules-center = ' + polybar['modules-center']) rl.replace_line(configuration['polybar-config'], 'modules-right', 'modules-right = ' + polybar['modules-right']) rl.replace_line( configuration['polybar-config'], 'label-unfocused-background', 'label-unfocused-background = ' + polybar['label-unfocused-background']) rl.replace_line( configuration['polybar-config'], 'label-unfocused-foreground', 'label-unfocused-foreground = ' + polybar['label-unfocused-foreground']) rl.replace_line( configuration['polybar-config'], 'label-focused-background', 'label-focused-background = ' + polybar['label-focused-background']) rl.replace_line( configuration['polybar-config'], 'label-focused-foreground', 'label-focused-foreground = ' + polybar['label-focused-foreground']) rl.replace_line( configuration['polybar-config'], 'label-visible-background', 'label-visible-background = ' + polybar['label-visible-background']) rl.replace_line( configuration['polybar-config'], 'label-visible-foreground', 'label-visible-foreground = ' + polybar['label-visible-foreground']) rl.replace_line( configuration['polybar-config'], 'label-mode-background', 'label-mode-background = ' + polybar['label-mode-background']) rl.replace_line( configuration['polybar-config'], 'label-mode-foreground', 'label-mode-foreground = ' + polybar['label-mode-foreground']) rl.replace_line( configuration['polybar-config'], 'format-foreground', 'format-foreground = ' + polybar['format-foreground']) rl.replace_line( configuration['polybar-config'], 'format-background', 'format-background = ' + polybar['format-background']) rl.replace_line( configuration['polybar-config'], 'label-open-foreground', 'label-open-foreground = ' + polybar['label-open-foreground']) rl.replace_line( configuration['polybar-config'], 'label-close-foreground', 'label-close-foreground = ' + polybar['label-close-foreground']) rl.replace_line( configuration['polybar-config'], 'label-separator-foreground', 'label-separator-foreground = ' + polybar['label-separator-foreground']) rl.replace_line( configuration['polybar-config'], 'format-connected-foreground', 'format-connected-foreground = ' + polybar['format-connected-foreground']) rl.replace_line( configuration['polybar-config'], 'format-connected-background', 'format-connected-background = ' + polybar['format-connected-background']) rl.replace_line( configuration['polybar-config'], 'format-connected-prefix-foreground', 'format-connected-prefix-foreground = ' + polybar['format-connected-prefix-foreground']) rl.replace_line( configuration['polybar-config'], 'ramp-signal-foreground', 'ramp-signal-foreground = ' + polybar['ramp-signal-foreground']) else: prnt.prnt('-f', 'Failed to locate polybar info in the JSON file') else: prnt.prnt('-f', 'Failed to locate your polybar configuration file')