예제 #1
0
def refresh_all( xresources, wallpaper):
    prnt.prnt( '-n', 'Refreshing i3 and xrdb and setting wallpaper')
    if wallpaper != '':
        call( ['nitrogen', '--set-zoom-fill', 'wallpapers/'+wallpaper])
    call( ['xrdb', xresources])
    call( ['i3-msg', 'restart'])
    prnt.prnt( '-s', 'Done!')
예제 #2
0
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')
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
def replace_line(file, pattern, new_line):
    if file.startswith('~'):
        file = path.expanduser(file)
    fh, abs_path = mkstemp()
    with fdopen(fh, 'w') as new_file:
        with open(file) as old_file:
            for line in old_file:
                if line.startswith(pattern):
                    pl1 = line
                    pl1 = pl1.rstrip()
                    pl2 = new_line
                    pl2 = pl2.rstrip()
                    prnt.prnt(
                        '-n',
                        'Replacing line: \'' + pl1 + '\' with \'' + pl2 + '\'')
                    #print (new_file.write( new_line+'\n' )=="None")
                    try:
                        new_file.write(new_line + '\n')
                        prnt.prnt('-s', 'Success!')
                    except:
                        prnt.prnt('-f', 'Failed!')
                else:
                    try:
                        new_file.write(line)
                        #prnt.prnt( '-s', 'Success!')
                    except:
                        prnt.prnt('-f', 'Failed!')
                #new_file.write( new_line if pattern in line else line)
    remove(file)
    move(abs_path, file)
예제 #7
0
def replace_theme(json_file, back, fore, wallpaper_file):
    prnt.prnt('-n', 'Replacing your theme configuration file')
    json_file["comment"]["back"] = back
    json_file["comment"]["fore"] = fore
    json_file['polybar']['background'] = back
    json_file['polybar']['foreground'] = fore
    json_file['polybar']['label-unfocused-background'] = back
    json_file['polybar']['label-unfocused-foreground'] = fore
    json_file['polybar']['label-mode-background'] = back
    json_file['polybar']['label-visible-background'] = back
    json_file['polybar']['format-background'] = back
    json_file['polybar']['format-connected-background'] = back
    json_file['polybar']['format-connected-foreground'] = fore
    json_file['wallpaper'] = wallpaper_file
    return json_file
예제 #8
0
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
예제 #9
0
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
예제 #10
0
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
예제 #11
0
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')
예제 #12
0
def copy_file_noconfig(old_file, new_file):
    prnt.prnt('-s', 'Located ' + old_file + ' file!')
    try:
        copyfile(old_file, new_file)
        prnt.prnt('-s', 'Installed the new file successfully!')
        return True
    except:
        prnt.prnt('-f', 'Failed to install the new file!')
        return False
예제 #13
0
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')
예제 #14
0
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')
예제 #15
0
def replace_line(file, pattern, new_line):
    fh, abs_path = mkstemp()
    with fdopen(fh, 'w') as new_file:
        with open( file ) as old_file:
            for line in old_file:
                if line.startswith( pattern ):
                    pl1 = line
                    pl1 = pl1.rstrip()
                    pl2 = new_line
                    pl2 = pl2.rstrip()
                    prnt.prnt( '-s', 'Replacing line: \''+pl1+'\' with \''+pl2+'\'')
                    if(new_file.write( new_line+'\n' )):
                        prnt.prnt( '-s', 'Success!')
                    else:
                        prnt.prnt( '-f', 'Failed!')
                else:
                    new_file.write( line )
                #new_file.write( new_line if pattern in line else line)
    remove(file)
    move(abs_path, file)
예제 #16
0
def replace_line(file, pattern, new_line):
    fh, abs_path = mkstemp()
    with fdopen(fh, 'w') as new_file:
        with open(file) as old_file:
            for line in old_file:
                if line.startswith(pattern):
                    pl1 = line
                    pl1 = pl1.rstrip()
                    pl2 = new_line
                    pl2 = pl2.rstrip()
                    prnt.prnt(
                        '-s',
                        'Replacing line: \'' + pl1 + '\' with \'' + pl2 + '\'')
                    if (new_file.write(new_line + '\n')):
                        prnt.prnt('-s', 'Success!')
                    else:
                        prnt.prnt('-f', 'Failed!')
                else:
                    new_file.write(line)
                #new_file.write( new_line if pattern in line else line)
    remove(file)
    move(abs_path, file)
예제 #17
0
def refresh_all(xresources, wallpaper):
    prnt.prnt('-n', 'Refreshing i3 and xrdb and setting wallpaper')
    call(['xrdb', xresources])
    call(['i3-msg', 'restart'])
    prnt.prnt('-s', 'Done!')
예제 #18
0
def install_defaults(temp_folder, configuration):
    prnt.prnt('-n', 'Intalling the files from ' + temp_folder + 'file.')

    if (fileu.locate_folder(temp_folder)):
        prnt.prnt('-n', 'Located the folder.')

        # Install default i3 file
        if 'i3-config' in configuration:
            if (install_file(configuration, 'i3-config',
                             temp_folder + 'i3.template')):
                prnt.prnt('-s', 'Success!')
            else:
                prnt.prnt('-f', 'Failed!')

        # Install default polybar file
        if 'polybar-config' in configuration:
            if (install_file(configuration, 'polybar-config',
                             temp_folder + 'polybar.template')):
                prnt.prnt('-s', 'Success!')
            else:
                prnt.prnt('-f', 'Failed!')

        # Install default Xresources file
        if 'xresources' in configuration:
            if (install_file(configuration, 'xresources',
                             temp_folder + 'xresources.template')):
                prnt.prnt('-s', 'Success!')
            else:
                prnt.prnt('-f', 'Failed!')
    else:
        prnt.prnt('-f', 'Failed to locate the folder.')
        exit(9)
예제 #19
0
def backup_config(backup_folder, configuration):
    prnt.prnt('-n', 'Backing up your files.')

    if (fileu.locate_folder(backup_folder)):
        prnt.prnt('-s', 'Located the backup folder.')

        # Backup i3 file
        if 'i3-config' in configuration:
            if (backup_file(configuration, 'i3-config',
                            backup_folder + '/i3.config')):
                prnt.prnt('-s', 'Success!')
            else:
                prnt.prnt('-f', 'Failed!')

        # Backup Polybr config
        if 'polybar-config' in configuration:
            if (backup_file(configuration, 'polybar-config',
                            backup_folder + '/polybar.config')):
                prnt.prnt('-s', 'Success!')
            else:
                prnt.prnt('-f', 'Failed!')

        # Backup xresources
        if 'xresources' in configuration:
            if (backup_file(configuration, 'xresources',
                            backup_folder + '/xresources')):
                prnt.prnt('-s', 'Success!')
            else:
                prnt.prnt('-f', 'Failed!')

    else:
        prnt.prnt('-f', 'Failed to locate the backup folder.')
        exit(9)
예제 #20
0
if __name__=="__main__":

    parser = argparse.ArgumentParser(description='create-theme by James Shane')
    parser.add_argument('-c','--config', type=str, required=True, help='Load config file')
    parser.add_argument('-t','--theme', type=str, required=True, help='Theme name')
    args = parser.parse_args()

    configuration = {}
    configuration = conf.read_config( args.config)
    print (configuration['json-template'])
    install.copy_file_noconfig(configuration['json-template'],args.theme+".json")
    #print (args.config)
    #print (args.theme)

    jfile = lj.load_json(args.theme+".jpg.json")
    back=jfile['pal']['1']
    prnt.prnt( '-n', 'Background is '+back)
    fore=jfile['pal']['2']
    prnt.prnt( '-n', 'Foreground is '+fore)

    data = lj.load_json(args.theme+".json")
    data=rt.replace_theme(data,back,fore,args.theme+".jpg")

    jfile=json.dumps(data, indent=4)
    with open(args.theme+".json", 'w') as outfile:
        #json.dump(jfile, outfile)
        outfile.write(jfile)

    exit(0)
예제 #21
0
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')
예제 #22
0
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')