|
#! /usr/bin/env python |
|
# -*- coding: utf-8 -*- |
|
|
|
template_intro = '''Windows Registry Editor Version 5.00 |
|
\n;-------------------------------------------------------------------- |
|
; Please review all this file BEFORE apply changes to your system. |
|
; I'm NOT responsable for any damage caused to your system. |
|
;--------------------------------------------------------------------''' |
|
|
|
template_reg = ''' |
|
\n; cria associacao de {descr} <.{ext}> |
|
[HKEY_CLASSES_ROOT\\.{ext}] |
|
@="file_{ext}" |
|
"PerceivedType"="text" |
|
"Content Type"="text/plain" |
|
\n[HKEY_CLASSES_ROOT\\file_{ext}] |
|
@="{descr}" |
|
"EditFlags"=dword:00040000 |
|
\n[HKEY_CLASSES_ROOT\\file_{ext}\\DefaultIcon] |
|
@="{iconpath}{icon}" |
|
\n[HKEY_CLASSES_ROOT\\file_{ext}\\shell\\open\\command] |
|
@="{executable} \\"%1\\""''' |
|
|
|
template_new = ''' |
|
\n; inclue <.{ext}> na lista de opcao do menu "Novo" do botao direito |
|
[HKEY_CLASSES_ROOT\\.{ext}\\ShellNew] |
|
"NullFile"=""''' |
|
|
|
template_unreg = ''' |
|
\n; remove associacao de <.{ext}> |
|
[-HKEY_CLASSES_ROOT\\.{ext}] |
|
[-HKEY_CLASSES_ROOT\\file_{ext}]''' |
|
|
|
|
|
template_context_file = ''' |
|
\n; quando clica botao direito num arquivo |
|
[HKEY_CLASSES_ROOT\*\shell\{name}] |
|
@="{caption}" |
|
"Icon"="{executable}" |
|
\n[HKEY_CLASSES_ROOT\*\shell\{name}\command] |
|
@="{executable} \"%1\""''' |
|
|
|
template_context_file_unreg = ''' |
|
\n; remove clique direito num arquivo |
|
[-HKEY_CLASSES_ROOT\*\shell\{name}]''' |
|
|
|
template_context_folder = ''' |
|
\n; quando clica botao direito numa pasta |
|
[HKEY_CLASSES_ROOT\Directory\shell\{name}] |
|
@="{caption}" |
|
"Icon"="{executable}" |
|
\n[HKEY_CLASSES_ROOT\Directory\shell\{name}\command] |
|
@="{executable} \"%1\""''' |
|
|
|
template_context_folder_unreg = ''' |
|
\n; remove clique direito num folder |
|
[-HKEY_CLASSES_ROOT\Directory\shell\{name}]''' |
|
|
|
template_context_background = ''' |
|
\n; quando clica botao direito numa parte vazia de uma pasta aberta |
|
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\{name}] |
|
@="{caption}" |
|
"Icon"="{executable}" |
|
\n[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\{name}\command] |
|
@="{executable} \"%V\""''' |
|
|
|
template_context_background_unreg = ''' |
|
\n; remove clique direito numa parte vazia da pasta |
|
[-HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\{name}]''' |
|
|
|
# -------------------------------------------------------------------------------------- |
|
|
|
import yaml |
|
|
|
data = yaml.load(open('assoc.yaml', 'r')) |
|
|
|
reg = open('register.reg', 'wt') |
|
unreg = open('unregister.reg', 'wt') |
|
reg.write(template_intro) |
|
unreg.write(template_intro) |
|
|
|
iconpath = repr(data['iconpath'])[1:-1] |
|
|
|
for prog in data['programs']: |
|
executable = repr(prog['exec'])[1:-1] |
|
|
|
if 'context' in prog: |
|
if 'name' in prog['context']: |
|
if 'file' in prog['context']: |
|
r = template_context_file.format(name=prog['context']['name'], caption=prog['context']['file'], executable=executable) |
|
reg.write(r) |
|
u = template_context_file_unreg.format(name=prog['context']['name']) |
|
unreg.write(u) |
|
|
|
if 'folder' in prog['context']: |
|
r = template_context_folder.format(name=prog['context']['name'], caption=prog['context']['folder'], executable=executable) |
|
reg.write(r) |
|
u = template_context_folder_unreg.format(name=prog['context']['name']) |
|
unreg.write(u) |
|
|
|
if 'background' in prog['context']: |
|
r = template_context_background.format(name=prog['context']['name'], caption=prog['context']['background'], executable=executable) |
|
reg.write(r) |
|
u = template_context_background_unreg.format(name=prog['context']['name']) |
|
unreg.write(u) |
|
|
|
for ext in prog['extensions']: |
|
r = template_reg.format(ext=ext[0], descr=ext[1], iconpath=iconpath, icon=ext[2], executable=executable) |
|
reg.write(r) |
|
|
|
if len(ext) == 4: |
|
if ext[3]: |
|
n = template_new.format(ext=ext[0]) |
|
reg.write(n) |
|
|
|
u = template_unreg.format(ext=ext[0]) |
|
unreg.write(u) |
|
|
|
reg.close() |
|
unreg.close() |