浏览代码

config sourcē labojumi

Ivars 6 年前
父节点
当前提交
cb3b60573f
共有 1 个文件被更改,包括 13 次插入9 次删除
  1. 13
    9
      sources/config.py

+ 13
- 9
sources/config.py 查看文件

@@ -15,18 +15,21 @@ class Source(SourceBase):
15 15
     def __init__(self,country="lv",cfg_path=None, cfg_file=""):
16 16
         self.name = "config"
17 17
         self.country=country
18
+        self.lists = collections.OrderedDict()
19
+        self.titles = {}
18 20
         if not cfg_file: cfg_file = "streams.cfg"
19 21
         cur_directory = os.path.dirname(os.path.abspath(__file__))
20 22
         if not cfg_path: cfg_path = cur_directory
21 23
         self.cfg_path = cfg_path
22
-        self.cfg_file = cfg_file
24
+        self.set_streams_file(cfg_file)
25
+        print "streams_file=", self.streams_file
26
+        self.read_streams()
27
+
28
+    def set_streams_file(self, cfg_file):
23 29
         if not ("/" in cfg_file or "\\" in cfg_file):  # ja tikai faila nosaukums, tad meklē to source folderi
24
-            self.streams_file = os.path.join(cfg_path,cfg_file)
30
+            self.streams_file = os.path.join(self.cfg_path,cfg_file)
25 31
         else:
26 32
             self.streams_file = cfg_file
27
-        self.lists = collections.OrderedDict()
28
-        self.titles = {}
29
-        self.read_streams()
30 33
 
31 34
     def get_content(self, data):
32 35
         print "[config] get_content",data
@@ -46,7 +49,7 @@ class Source(SourceBase):
46 49
             try:
47 50
                 sf = urllib2.urlopen(self.streams_file, "r")
48 51
             except Exception as e:
49
-                raise Exception("Can not open streams file %s" % self.cfg_file)
52
+                raise Exception("Can not open streams file %s" % self.streams_file)
50 53
                 #print "Warning: can not open streams file %s, callback to default" % self.streams_file
51 54
                 #self.streams_file = os.path.join(self.cfg_path, "streams.cfg")
52 55
                 #sf = open(self.streams_file, "r")
@@ -117,8 +120,6 @@ class Source(SourceBase):
117 120
         else:
118 121
             f.close()
119 122
 
120
-
121
-
122 123
     def get_lists(self):
123 124
         return self.lists.keys()
124 125
 
@@ -154,7 +155,9 @@ class Source(SourceBase):
154 155
 
155 156
     def move_item(self, name, pos, pos2):
156 157
         # l.insert(newindex, l.pop(oldindex))
157
-        if pos2 < pos:
158
+        if pos2 == None:
159
+            self.lists[name].append(self.lists[name].pop(pos))
160
+        elif pos2 < pos:
158 161
             self.lists[name].insert(pos2, self.lists[name].pop(pos))
159 162
         elif pos2 > pos:
160 163
             self.lists[name].insert(pos2-1, self.lists[name].pop(pos))
@@ -162,6 +165,7 @@ class Source(SourceBase):
162 165
 if __name__ == "__main__":
163 166
 
164 167
     source = Source(cfg_file="ftp://user:Kaskade7@home.blue.lv/hdd/streams.cfg")
168
+    #source = Source(cfg_file="streams.cfg")
165 169
     source.read_streams()
166 170
     source.write_streams()
167 171
     import sys