Skip to content

Instantly share code, notes, and snippets.

@danfate
Forked from rashkur/chrome_icon_fixer
Last active August 29, 2015 14:27
Show Gist options
  • Save danfate/fb51a97079d56042341e to your computer and use it in GitHub Desktop.
Save danfate/fb51a97079d56042341e to your computer and use it in GitHub Desktop.

Revisions

  1. @rashkur rashkur created this gist Sep 7, 2014.
    34 changes: 34 additions & 0 deletions chrome_icon_fixer
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    import ConfigParser, mmap

    config_file = "/usr/share/applications/google-chrome.desktop"
    add_string_to_each_section = ["StartupWMClass", "Google-chrome-stable"]
    option = add_string_to_each_section[0]
    value = add_string_to_each_section[1]


    class Fixer:
    def check(self, cf, option, value):
    f = open(cf)
    s = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
    if s.find(option+" = "+value) != -1:
    print "already fixed"
    exit(1)

    def fix(self, cf, option, value):
    Config = ConfigParser.ConfigParser()
    Config.optionxform=str
    Config.read(cf)

    cfgfile = open(cf,'w')

    for section in range(len(Config.sections())):
    Config.set(Config.sections()[section], option, value)

    Config.write(cfgfile)
    cfgfile.close()


    if __name__ == "__main__":
    F = Fixer()
    F.check(config_file, option, value)
    F.fix(config_file, option, value)