new bluetooth script
[dotfiles_afify.git] / .scripts / bar_scripts / unused / read_file.py
blob0ce72a5bf3a6caae353a6f61584507f105cc3e58
1 #!/usr/bin/env python2.7
3 import os
4 import re
5 import linecache
8 def find_the_line():
9 pattern = re.compile(current_file_name)
11 for i, line in enumerate(open(tint2_config_path, 'r')):
12 for match in re.finditer(pattern, line):
13 # print 'Found on line %s: %s' % (i+1, match.groups())
14 return int(i+1)
17 def get_line_data(file_name, line):
18 """Open file go to line and return data."""
19 line = linecache.getline(file_name, line)
20 return line
23 def find_color_from_string(the_string):
24 """Search in a string for a patter #.*."""
25 p = re.compile("(#.{6})")
26 result = p.search(the_string)
27 return result.group(1)
30 def get_color():
31 """Open find."""
32 ram_color = find_color_from_string(
33 get_line_data(
34 file_name=tint2_config_path, line=color_line))
36 if ram_color == red:
37 result = "is red"
38 elif ram_color == default_color:
39 result = "default_color"
40 else:
41 result = False
42 return result
45 def change_to_color(color):
46 with open(tint2_config_path, 'r') as file:
47 lines = file.readlines()
49 the_new_line = "execp_font_color = " + color + " 100"
50 lines[color_line-1] = the_new_line + "\n"
52 with open(tint2_config_path, 'w') as file:
53 file.writelines(lines)
56 current_file_name = os.path.basename(__file__)
57 restart = "killall -SIGUSR1 tint2"
58 red = "#ff0000"
59 default_color = "#d8d8d8"
61 tint2_config_path = "/home/hassan/Dropbox/development/linux_conf/openbox/tint2/test_color/tint2rc"
62 color_line = (find_the_line()+13)
64 # print color_line
65 change_to_color(default_color)
66 print get_color()
69 # if ram > 10 :
70 # if get_color() == default_color:
71 # change_to_red()
72 # elif get_ram_color() == red:
73 # pass