xsession skeleton

This commit is contained in:
ville rantanen
2015-06-03 08:39:56 +03:00
parent 57771e1e8d
commit ca1b5b2d0b
3 changed files with 42 additions and 23 deletions

View File

@@ -1,11 +1,7 @@
#!/usr/bin/python
import sys
import os
import re
import sys,re,os
from argparse import ArgumentParser
from argparse import RawTextHelpFormatter
def setup_options():
parser=ArgumentParser(description="""Template Filler
@@ -16,6 +12,8 @@ def setup_options():
== Value file/Value pair example: ==
[[name]]=John
""",formatter_class=RawTextHelpFormatter)
parser.add_argument("-e",action="store_true",dest="env",default=False,
help="Use the environment to replace ${env} style variables.")
parser.add_argument("-f",action="store",dest="file",
help="File name to read keys/values.")
parser.add_argument("-p",action="append",dest="values",default=[],
@@ -49,21 +47,20 @@ def parse_arguments(args):
pairs.append( (tokens[0], tokens[1].decode('string_escape')) )
return pairs
def main():
options=setup_options();
pairs=[]
if options.file!=None:
pairs.extend(parse_file(options.file))
pairs.extend(parse_arguments(options.values))
if options.template==None:
in_reader=sys.stdin
else:
in_reader=open(options.template,'rb')
for l in in_reader:
for p in pairs:
l=l.replace(p[0],p[1])
sys.stdout.write(l)
if __name__ == "__main__":
main()
options=setup_options();
pairs=[]
if options.file!=None:
pairs.extend(parse_file(options.file))
pairs.extend(parse_arguments(options.values))
if options.template==None:
in_reader=sys.stdin
else:
in_reader=open(options.template,'rb')
for l in in_reader:
for p in pairs:
l=l.replace(p[0],p[1])
if options.env:
var_list=[m.group(0) for m in re.finditer('\${[^ ]+}', l)]
for v in var_list:
l=l.replace(v,os.environ.get(v[:-1][2:],""))
sys.stdout.write(l)

13
skel/xsessionrc Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/bash
#sleep 1
#$HOME/bin/disp 4
# Do something if at Univ network
#if ping ad.helsinki.fi -c 2; then
# true
#fi
true

9
skel/xsessionrc.desktop Normal file
View File

@@ -0,0 +1,9 @@
[Desktop Entry]
Name=Session startup script
Comment=Edit to suit your settings
Exec=${HOME}/bin/xscreenrc
Terminal=false
Type=Application
Icon=preferences-desktop-theme
Categories=Settings
StartupNotify=false