Libellés

mercredi 23 février 2011

Groovy : Client Rest avec authentification basic + SSL + UTF8

Voici un exemple d'utilisation de l'API Groovy RestClient (extension de HTTPBuilder) avec :

  • authentification Basic

  • connexion sécurisé over SSL

  • utilisation du charset UTF8



Maintenant place au code :

import groovyx.net.http.*

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.1' )

def urlStr = "https://blabla.com"
def content = '{"key":"value"}'
def login = "myLogin"
def password = "myPassword"

def http = new RESTClient(urlStr)
http.encoderRegistry = new EncoderRegistry(charset: "utf-8")
http.auth.basic login, password
def response = http.put(requestContentType: ContentType.JSON, body: content)
if (response.status != 204) {
log.warn("Operation failed: " + response.status + ", on url " + urlStr + ", with content : " + response.data);
}

mardi 22 février 2011

wmfs : présentation, installation configuration

J'ai installé hier wmfs :
http://wmfs.info/projects/2/wiki/WmfsDeb


Comme son nom l'indique wmfs est un window manager (il remplacera votre gnome, kde, openbox, ...)


Wmfs a comme particularité :
  - d'utiliser nativement le taling (je l'explique plus bas)
  - d'avoir un fichier de configuration très simple (raccourci clavier, autostart, fond d'écran, menu, traybar, ... tout est configurable simplement)
  - d'avoir une tray barre en mode texte
  - d'avoir un lanceur d'application intégré : Alt - p




Qu'est ce que le tiling ?
------------------------------
Si vous en avez marre de chercher vos fenêtres qui sont toute les unes en dessous des autres, le tilling est fait pour vous.


Le titling organise chacune de vos fenetre dans une grille prédéfinie.



Pas très sexy mais très pratique car on voit toute les fenêtres ouvertes. Ensuite il suffit de s'organiser des bureaux pour trier toutes les fenêtres.

Afin de ne pas trop galérer, je vous conseille d'apprendre les raccourcis claviers par coeur. Ils permettent par exemple de déplacer les fenêtres, d'en agrandir certaine, de gérer les bureaux, ...


Le fichier de configuration 
-----------------------------------

$ cat .config/wmfs/wmfsrc
[misc]
        font               = "dejavu-10"
        raisefocus         = false
        raiseswitch        = false
        focus_follow_mouse = true
        opacity            = 255
        focus_pointer_click = true
### Grace au script status.sh, on actualise la tray barre toute les secondes
        status_timing      = 1     #seconds
        status_path       = "~/.config/wmfs/status.sh"
[/misc]
[bar]
        bg     = "#191919"
        fg     = "#ffffff"
        border = true
### On active la tray barre
        [systray]
                # Enable/disable systray
                active = true
                # Screen of systray
                screen = 0
                # Spacing between tray icons
                spacing = 3
        [/systray]
[/bar]
[layouts]
        fg = "#191919"
        bg = "#ffffff"
        # Border around the layout button.
        border = false
        # Value menu or switch.
        system = "switch"
        # Value left or right.
        placement = "right"
        # Keep layout geo for free layout
        keep_layout_geo = false
        # Symbol displayed for the selected layout in the list
        selected_layout_symbol = "*"
        # Width of layout button
        # layout_button_width = x
        # Tiling layouts.
        [layout] type = "tile_right"         symbol = "RIGHT"    [/layout]
        [layout] type = "tile_left"          symbol = "LEFT"     [/layout]
        [layout] type = "tile_top"           symbol = "TOP"      [/layout]
        [layout] type = "tile_bottom"        symbol = "BOTTOM"   [/layout]
        [layout] type = "tile_grid"          symbol = "GRID_H"   [/layout]
        [layout] type = "tile_grid_vertical" symbol = "GRID_V"   [/layout]
        [layout] type = "mirror_vertical"    symbol = "MIRROR_V" [/layout]
        [layout] type = "mirror_horizontal"  symbol = "MIRROR_H" [/layout]
        # Other layouts.
        [layout] type = "max"   symbol = "MAX"  [/layout]
        [layout] type = "free"  symbol = "FREE" [/layout]
[/layouts]
[tags]
        [default_tag]
             name             = "new tag"
             mwfact           = 0.5
             nmaster          = 1
             layout           = "tile_right"
             resizehint       = false
             infobar_position = "bottom"
        [/default_tag]
        # whether client_next on the last tag will send you on the first
        # and client_prev on the first tag will send you on the last one
        tag_round      = false
        # Going twice on the same tag will bring you back on the previous one
        tag_auto_prev  = false
        occupied_bg    = "#cccccc"
        occupied_fg    = "#000000"
        sel_fg         = "#191919"
        sel_bg         = "#ffffff"
        urgent_bg      = "#DD1111"
        urgent_fg      = "#000000"
        # If true, number of the tag will be used for name
        name_count     = false
        #default_name   = "new tag" # deprecated, use [default_tag] instead
        #default_layout = "tile_right" # deprecated, use [default_tag] instead
        # Border around the tag buttons.
        border      = true
### Afin de masquer les bureaux non utilisés
        autohide    = true
        # Mouse buttons action on tag.
        mouse_button_tag_sel       = "1"
        mouse_button_tag_transfert = "2"
        mouse_button_tag_add       = "3"
        mouse_button_tag_next      = "4"
        mouse_button_tag_prev      = "5"
### On défini les noms des bureaux
        [tag] name = "Web"   [/tag]
        [tag] name = "two"   [/tag]
        [tag] name = "three" [/tag]
        [tag] name = "four"  [/tag]
        [tag] name = "five"  [/tag]
        [tag] name = "six"   [/tag]
        [tag] name = "seven" [/tag]
        [tag] name = "eight" [/tag]
        [tag] name = "nine"  [/tag]
[/tags]
[root]
### On transforme la background_command en autostart.sh afin de lancer ce que l'on veut au démarrage de wmfs
        background_command = "$HOME/.config/wmfs/autostart.sh &"
        [mouse] button = "4" func = "tag_next"              [/mouse]
        [mouse] button = "5" func = "tag_prev"              [/mouse]
        [mouse] button = "3" func = "menu" cmd = "rootmenu" [/mouse]
[/root]
[client]
        client_round         = true
        client_auto_center   = false
        border_height        = 0
        border_shadow        = false
        border_normal        = "#191919"
        border_focus         = "#191919"
        place_at_mouse       = false
        resize_corner_normal = "#191919"
        resize_corner_focus  = "#191919"
        set_new_win_master   = true
        client_tile_raise    = false
        new_client_get_mouse = false
        # send all client that have no tag rule in this default tag
        #default_open_tag     = 4
        # same as above but for the screen
        #default_open_screen  = 1
        # Space between tiled clients
        padding = 0
        # Modifier for mouse use
        modifier = "Alt"
        # *DEPRECATED* but works, see [rules] section
        # Set automatic free or max client
        # autofree = "xterm|MPlayer"
        # automax  = "Navigator"
        [mouse] button = "1" func = "client_raise" [/mouse]
        [mouse] button = "1" func = "mouse_move"   [/mouse]
        [mouse] button = "3" func = "client_raise" [/mouse]
        [mouse] button = "3" func = "mouse_resize" [/mouse]
#### On enlève la barre de titre car la souris c'est triché
#        [titlebar]
#                stipple   = false
#                height    = 12
#                fg_normal = "#7E89A2"
#                fg_focus  = "#9F9AB3"
#
#                [mouse] button = "1" func = "client_raise" [/mouse]
#                [mouse] button = "1" func = "mouse_move"   [/mouse]
#                [mouse] button = "3" func = "client_raise" [/mouse]
#                [mouse] button = "3" func = "mouse_resize" [/mouse]
#
#                [button]
#                        # Available "free", "max", "tile" flags or button.
#                        flags = "free,max,tile"
#                        [mouse] button = "1" func = "client_kill"             [/mouse]
#                        [mouse] button = "3" func = "menu" cmd = "clientmenu" [/mouse]
#
#                        [line] coord = {1, 1, 4, 1} [/line]
#                        [line] coord = {1, 1, 1, 4} [/line]
#                        [line] coord = {1, 4, 4, 4} [/line]
#                [/button]
#        [/titlebar]
[/client]
[rules]
       [rule]
               instance      = "xv"       # First part of WM_CLASS
               class         = "MPlayer"  # Seconf part of WM_CLASS, not needed if first part is correct
               # role        = ""         # WM_WINDOW_ROLE
               screen        = 0          # Screen to use
               tag           = 2          # Tag number of apps
               free          = true       # Set automatic free client
               max           = false      # Set automatic maximized client
               follow_client = false      # follow the client
               ignore_tags   = false      # ignore tag (free mode)
               follow_client = false      # if the client open in an other tag/screen, follow it.
       [/rule]
[/rules]
[menu]
        # Default menu, binded on the root window, button 3.
        [set_menu]
                name = "rootmenu"
                # place_at_mouse = false
                # x = 40 y = 50
                # Available "center", "left", "right" menu align. Default: "center".
                align = "left"
                fg_focus  = "#191919" bg_focus  = "#7E89A2"
                fg_normal = "#9F9AB3" bg_normal = "#191919"
### On ne laisse que le minimum dans le menu
                [item] name = "Terminal"        func = "spawn" cmd = "urxvt || xterm || gnome-terminal" [/item]
                [item] name = "Editeur"        func = "spawn" cmd = "gedit || kwrite || leafpad" [/item]
                [item] name = "Web"        func = "spawn" cmd = "chromium || firefox || opera" [/item]
                #[item] name = "Applications" submenu = "appmenu"                   [/item]
                #[item] name = "Next tag"        func = "tag_next"                  [/item]
                #[item] name = "Previous tag"    func = "tag_prev"                  [/item]
                #[item] name = "Next layout"     func = "layout_next"               [/item]
                #[item] name = "Previous layout" func = "layout_prev"               [/item]
                #[item] name = "Toggle infobar"  func = "toggle_infobar_position"   [/item]
                #[item] name = "Quit WMFS"       func = "quit"                      [/item]
        [/set_menu]
        [set_menu]
                name = "appmenu"
                align = "left"
                fg_focus  = "#191919" bg_focus  = "#7E89A2"
                fg_normal = "#9F9AB3" bg_normal = "#191919"
                [item] name = "Web"         func = "spawn" cmd = "chromium"     [/item]
        [/set_menu]
        [set_menu]
                name = "clientmenu"
                fg_focus  = "#D4D4D4" bg_focus  = "#003366"
                fg_normal = "#D4D4D4" bg_normal = "#191919"
                # Check items: possible 'check_max' or 'check_free'.
                [item] name = "Close"    func = "client_kill"                      [/item]
                [item] name = "Maximize" func = "toggle_max"  check = "check_max"  [/item]
                [item] name = "Free"     func = "toggle_free" check = "check_free" [/item]
        [/set_menu]
[/menu]
[launcher]
        [set_launcher]
                # Limit size of the launcher window (px)
                width_limit = 300
                name = "launcher_exec"
                prompt = "Exec: "
                command = "exec"
        [/set_launcher]
        #ViWMFS : manage wmfs with vi-based command.
        [set_launcher]
                name = "viwmfs"
                prompt = "> "
                command = "wmfs -V"
        [/set_launcher]
[/launcher]
[keys]
         # Reload the configuration of wmfs.
        [key] mod = {"Alt", "Control"} key = "r" func = "reload" [/key]
        # Open a terminal.
        [key] mod = {"Control"} key = "Return" func = "spawn" cmd = "urxvt" [/key]
        # Kill the selected client.
        [key] mod = {"Alt"} key = "q" func = "client_kill" [/key]
        # Quit wmfs.
        [key] mod = {"Control", "Alt", "Shift"} key = "q" func = "quit" [/key]
        # Swap current client with the next.
        [key] mod = {"Alt"} key = "t" func = "client_swap_next" [/key]
        # Swap current client with the previous.
        [key] mod = {"Alt", "Shift"} key = "t" func = "client_swap_prev" [/key]
        # Toggle maximum the selected client
        [key] mod = {"Alt"} key = "m" func = "toggle_max" [/key]
        # Toggle free the selected client.
        [key] mod = {"Alt"} key = "f" func = "toggle_free" [/key]
        # Toggle the position of the infobar.
        [key] mod = {"Alt"} key = "b" func = "toggle_infobar_position" [/key]
        [key] mod = {"Alt", "Shift"} key = "b" func = "toggle_infobar_display" [/key]
        # Toggle the resizehint of the current tag/screen
        [key] mod = {"Shift", "Control"} key = "r" func = "toggle_resizehint" [/key]
        # Toggle the tag_autohide mode
        [key] mod = {"Shift", "Control"} key = "t" func = "toggle_tagautohide" [/key]
        # Select the next client.
        [key] mod = {"Alt"} key = "Tab" func = "client_next" [/key]
        # Select the previous client.
        [key] mod = {"Alt","Shift"} key = "Tab" func = "client_prev" [/key]
        # Select the next tag.
        [key] mod = {"Control"} key = "Right" func = "tag_next" [/key]
        # Select the previous tag.
        [key] mod = {"Control"} key = "Left" func = "tag_prev" [/key]
        # Select the next visible tag.
        [key] mod = {"Control","Alt"} key = "Right" func = "tag_next_visible" [/key]
        # Select the previous visible tag.
        [key] mod = {"Control","Alt"} key = "Left" func = "tag_prev_visible" [/key]
        # Set the next layout.
        [key] mod = {"Alt"} key = "space" func = "layout_next" [/key]
        # Set the previous layout.
        [key] mod = {"Alt", "Shift"} key = "space" func = "layout_prev" [/key]
        # Increase mwfact.
        [key] mod = {"Alt"} key = "l" func = "set_mwfact" cmd = "+0.025" [/key]
        # Decrease mwfact.
        [key] mod = {"Alt"} key = "h" func = "set_mwfact" cmd = "-0.025" [/key]
        # Increase nmaster.
        [key] mod = {"Alt"} key = "d" func = "set_nmaster" cmd = "+1" [/key]
        # Decease nmaster.
        [key] mod = {"Alt", "Shift"} key = "d" func = "set_nmaster" cmd = "-1" [/key]
        #Launcher.
        [key] mod = {"Alt"} key = "p" func = "launcher" cmd = "launcher_exec" [/key]
        #ViWMFS
        [key] mod = {"Alt"} key = "Escape" func = "launcher" cmd = "viwmfs" [/key]
        # Set the tag x.
        [key] mod = {"Alt"} key = "F1" func = "tag" cmd = "1" [/key]
        [key] mod = {"Alt"} key = "F2" func = "tag" cmd = "2" [/key]
        [key] mod = {"Alt"} key = "F3" func = "tag" cmd = "3" [/key]
        [key] mod = {"Alt"} key = "F4" func = "tag" cmd = "4" [/key]
        [key] mod = {"Alt"} key = "F5" func = "tag" cmd = "5" [/key]
        [key] mod = {"Alt"} key = "F6" func = "tag" cmd = "6" [/key]
        [key] mod = {"Alt"} key = "F7" func = "tag" cmd = "7" [/key]
        [key] mod = {"Alt"} key = "F8" func = "tag" cmd = "8" [/key]
        [key] mod = {"Alt"} key = "F9" func = "tag" cmd = "9" [/key]
        # Transfert selected client to x.
        [key] mod = {"Alt", "Shift"} key = "F1" func = "tag_transfert" cmd ="1" [/key]
        [key] mod = {"Alt", "Shift"} key = "F2" func = "tag_transfert" cmd ="2" [/key]
        [key] mod = {"Alt", "Shift"} key = "F3" func = "tag_transfert" cmd ="3" [/key]
        [key] mod = {"Alt", "Shift"} key = "F4" func = "tag_transfert" cmd ="4" [/key]
        [key] mod = {"Alt", "Shift"} key = "F5" func = "tag_transfert" cmd ="5" [/key]
        [key] mod = {"Alt", "Shift"} key = "F6" func = "tag_transfert" cmd ="6" [/key]
        [key] mod = {"Alt", "Shift"} key = "F7" func = "tag_transfert" cmd ="7" [/key]
        [key] mod = {"Alt", "Shift"} key = "F8" func = "tag_transfert" cmd ="8" [/key]
        [key] mod = {"Alt", "Shift"} key = "F9" func = "tag_transfert" cmd ="9" [/key]
        # Toggle additional tags (x) on the current tag
        [key] mod = {"Alt", "Super"} key = "F1" func = "tag_toggle_additional" cmd ="1" [/key]
        [key] mod = {"Alt", "Super"} key = "F2" func = "tag_toggle_additional" cmd ="2" [/key]
        [key] mod = {"Alt", "Super"} key = "F3" func = "tag_toggle_additional" cmd ="3" [/key]
        [key] mod = {"Alt", "Super"} key = "F4" func = "tag_toggle_additional" cmd ="4" [/key]
        [key] mod = {"Alt", "Super"} key = "F5" func = "tag_toggle_additional" cmd ="5" [/key]
        [key] mod = {"Alt", "Super"} key = "F6" func = "tag_toggle_additional" cmd ="6" [/key]
        [key] mod = {"Alt", "Super"} key = "F7" func = "tag_toggle_additional" cmd ="7" [/key]
        [key] mod = {"Alt", "Super"} key = "F8" func = "tag_toggle_additional" cmd ="8" [/key]
        [key] mod = {"Alt", "Super"} key = "F9" func = "tag_toggle_additional" cmd ="9" [/key]
        # change screen
        [key] mod = {"Super"} key = "Tab" func = "screen_next" [/key]
        [key] mod = {"Super", "Shift"} key = "Tab" func = "screen_prev" [/key]
        # swap client in the next/prev screen
        [key] mod = {"Super", "Shift"} key = "a" func = "client_screen_next" [/key]
        [key] mod = {"Super", "Shift"} key = "z" func = "client_screen_prev" [/key]
        # unlisted fonctions that can be used in [key] func = ""
        # client_focus_{right, left, top, bottom}
        # client_ignore_tag # Toggle the client in ignore_tag (display the client on all tags)
        # tag_prev_sel # go back to the previous selected tag
        # tag_transfert_{next, prev}
        # tag_urgent # go to the urgent tag
        # tag_swap_{next, prev} # swap tag with the previous/next one
        # tag_last # go to the last tag
        # tag_stay_last # toggle the current tag as the last one
        # toggle_abovefc
        # screen_prev_sel # go to the previous screen selected
        # set_layout # set layout. need to be called with cmd = ""
        # ignore_next_client_rules # ignore the rule the next time a rule is called
#### On ajoute quelques raccourcis clavier pour gérer le son.
[key] mod = {""} key = "XF86AudioMute" func = "spawn"   cmd = "mute" [/key] #mute/unmute
[key] mod = {""} key = "XF86AudioLowerVolume" func = "spawn"   cmd = "aumix -v -5" [/key] #augmenter le volume
[key] mod = {""} key = "XF86AudioRaiseVolume" func = "spawn"   cmd = "aumix -v +5" [/key] #Reduire le volume
[/keys]





Maintenant on configure le systray : Etat de la batterie, volume du son, heure.
J'apprecie vraiment que le systray soit en mode texte, car on fait vraiment ce que l'on veut avec.



$ cat .config/wmfs/status.sh



#!/bin/sh
DATE=`date +%H:%M`
POWER=`acpi -b | sed "s/Battery 0: //g" `
VOLUME=`aumix -v q|sed "s/,.*//g"`


wmfs -s "${POWER} | ${VOLUME} | ${DATE}"



Maintenant on lance certaine applications dès le lancement de wmfs, (également après chaque réactualisation de wmfs via Ctrl + Alt + r )
$ cat .config/wmfs/autostart.sh 
#!/bin/sh
xsetroot -solid black
if [ -z "$(pgrep chromium)" ]
  then
    chromium&
fi


Pour lancer wmfs automatiquement après s'être logué, il suffit de créer le fichier : 
$ echo "exec ck-launch-session wmfs" > ~/.xinitrc


Pour démarrer X sans se loguer, il suffit de modifier le fichier : 
### Il faut commenter
#id:3:initdefault:
### Il faut décommenter
id:5:initdefault:
...
### ll faut ajouter ceci, en spécifiant un USER-NAME
x:5:once:/bin/su -l -c '/usr/bin/startx -- -nolisten tcp -br -deferglyphs 16