Add manifest to manifest
[gpytage.git] / helper.py
blobd3bab967803be8ee01e072cd1fb438376b51adf5
1 #!/usr/bin/env python
3 # GPytage helper.py module
5 ############################################################################
6 # Copyright (C) 2008 by Kenneth Prugh #
7 # ken69267@gmail.com #
8 # #
9 # This program is free software; you can redistribute it and#or modify #
10 # it under the terms of the GNU General Public License as published by #
11 # the Free Software Foundation under version 2 of the license. #
12 # #
13 # This program is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU General Public License for more details. #
17 # #
18 # You should have received a copy of the GNU General Public License #
19 # along with this program; if not, write to the #
20 # Free Software Foundation, Inc., #
21 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
22 ############################################################################
24 import os
25 import pygtk; pygtk.require("2.0")
26 import gtk
27 from config import get_config_path, config_files
28 import config
29 import os
31 def folder_scan():
32 """ Return files and directories in the portage config path """
33 config_path = get_config_path()
34 dirs = []
35 file = []
36 for i in config_files:
37 result = os.path.isdir(config_path+i)
38 if(result):
39 dirs.append(i)
40 elif(os.access(config_path+i, os.F_OK)):
41 file.append(i)
42 else:
43 print "%s DOES NOT EXIST" % i
44 continue
45 return dirs, file
47 def folder_walk(dir):
48 """ Return list of files in specified directory """
49 config_path = get_config_path()
50 dir_files = []
51 for i in os.listdir(config_path+dir):
52 dir_files.append(i)
53 return dir_files
55 def reload():
56 """ Perform a revert, load saved data """
57 import datastore
58 datastore.datastore.clear()
59 for name, store in datastore.lists.iteritems():
60 store.clear()
61 datastore.create_treeiter()
62 datastore.create_lists()
63 from window import title
64 title("GPytage")
66 def scan_contents(arg):
67 """ Return data in specified file """
68 config_path = get_config_path()
70 try:
71 f=open(config_path+arg, 'r')
72 contents = f.readlines()
73 f.close()
74 except IOError: #needed or everything breaks
75 print 'HELPER: scan_contents(); Warning: Critical file %s%s not found' % (config_path, arg)
77 data = [] #list of list: eg [['python','x86']]
78 for i in contents:
79 if i.startswith('#'): #don't split if its a comment
80 new = [i, None]
81 else:
82 new = i.split(None,1)
83 data.append(new)
84 return data #return the master list of lists