wplayer

Check-in [14a0ab9378]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Dynamic reload of index contents.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:14a0ab9378c7ff5c2a94a2a166408fe5e9c0489587f0fc2198a42226505bb7d2
User & Date: ajv-899-334-8894@vsta.org 2017-04-22 03:41:43
Context
2017-06-24
04:33
Deal with non-ASCII file names check-in: 0544a82571 user: ajv-899-334-8894@vsta.org tags: master, trunk
2017-04-22
03:41
Dynamic reload of index contents. check-in: 14a0ab9378 user: ajv-899-334-8894@vsta.org tags: master, trunk
03:41
Support ES5 for now, Tint browser on tablet check-in: ad7942058e user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to get.py.

4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
...
119
120
121
122
123
124
125












126
127
128
129
130
131
132
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#
# Structure of paths in the server:
#  /
#	Main UI.  Top part is playlist, bottom is file/dir browser
#  /media/<prefix>/...
#	For each prefix of files, its contents is served by
#	way of its path under here.
import os, stat, urllib


# Max search results when filtering
MAXSEARCH=20

# The GET part of our handling
class GET_mixin(object):

................................................................................
            return False,None

        # Which tree are we accessing?  Get its file index
	pp = tuple(urllib.unquote(p) for p in self.paths)
        d = self.get_cpath(pp[1])
        if (d is None) or ('_index' not in d):
            return False,None













        # Walk forward to part of tree which matches our
        #  current position

        # Sweep results
        matches = []
        s = s.lower()
................................................................................
            prefix = ''
            plen = 0
            reached = True

        # Walk index entries
        # tup[0] is the actual path name (mixed case), tup[1]
        #  is the version with case flattened to lower only.
        for tup in d['_index']:
            # Still walking forward to reach prefix match
            l = tup[0]
            if not reached:
                if not l.startswith(prefix):
                    continue
                reached = True








|
>







 







>
>
>
>
>
>
>
>
>
>
>
>







 







|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#
# Structure of paths in the server:
#  /
#	Main UI.  Top part is playlist, bottom is file/dir browser
#  /media/<prefix>/...
#	For each prefix of files, its contents is served by
#	way of its path under here.
import os, sys, stat, urllib
import utils

# Max search results when filtering
MAXSEARCH=20

# The GET part of our handling
class GET_mixin(object):

................................................................................
            return False,None

        # Which tree are we accessing?  Get its file index
	pp = tuple(urllib.unquote(p) for p in self.paths)
        d = self.get_cpath(pp[1])
        if (d is None) or ('_index' not in d):
            return False,None

        # Refresh the cache if needed
        fn,ftm,entries = d['_index']
        try:
            newtm = os.stat(fn).st_mtime
            if newtm > ftm:
                sys.stderr.write("Reloading index %s\n" % (fn,))
                fn,ftm,entries = d['_index'] = utils.load_index(fn)
        except:
            # Just keep what we have, maybe somebody's moving
            #  the file right now?
            pass

        # Walk forward to part of tree which matches our
        #  current position

        # Sweep results
        matches = []
        s = s.lower()
................................................................................
            prefix = ''
            plen = 0
            reached = True

        # Walk index entries
        # tup[0] is the actual path name (mixed case), tup[1]
        #  is the version with case flattened to lower only.
        for tup in entries:
            # Still walking forward to reach prefix match
            l = tup[0]
            if not reached:
                if not l.startswith(prefix):
                    continue
                reached = True

Changes to main.py.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
# main.py
#	Main driver for WWW-Usenet interface
#
import sys, time, os
import chore

from get import GET_mixin
from chore.authen import Authen_mixin, Authen_Server_mixin

# Tie our various handlers together
class App_Handler(chore.handlers.Chore_Handler, GET_mixin,
        Authen_mixin):
    def __init__(self, conn, tup, approot):
	chore.handlers.Chore_Handler.__init__(self, conn, tup, approot,
	    (GET_mixin.__init__,
             Authen_mixin.__init__))

# Load file index into memory
# This should be a flat text file, sorted, which we will use
#  to provide search
def load_index(fn):
    f = open(fn, 'r')
    # Ugh, we need both the original path, and the case-flattened
    #  variant for loose search matching
    idx = tuple( (l.strip(), l.strip().lower()) for l in f )
    f.close()
    return idx

# Load our configuration file
#
# This includes configuring our config file elements,
#  then processing the supplied file.
def load_cfg(fn):

    # A configurator
................................................................................
    cfg = c.load_cfg(fn)

    # Preload any file indices
    for tup in cfg["files"]:
        d = tup[1]["path"]
        fn = d + ".idx"
        if os.access(fn, os.R_OK):
            tup[1]["_index"] = load_index(fn)
    return cfg

# Root of our app server
class App(chore.server.Server, Authen_Server_mixin):

    def __init__(self, config):
	# Let Chore handle most things






>











<
<
<
<
<
<
<
<
<
<
<







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18











19
20
21
22
23
24
25
..
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
# main.py
#	Main driver for WWW-Usenet interface
#
import sys, time, os
import chore
import utils
from get import GET_mixin
from chore.authen import Authen_mixin, Authen_Server_mixin

# Tie our various handlers together
class App_Handler(chore.handlers.Chore_Handler, GET_mixin,
        Authen_mixin):
    def __init__(self, conn, tup, approot):
	chore.handlers.Chore_Handler.__init__(self, conn, tup, approot,
	    (GET_mixin.__init__,
             Authen_mixin.__init__))












# Load our configuration file
#
# This includes configuring our config file elements,
#  then processing the supplied file.
def load_cfg(fn):

    # A configurator
................................................................................
    cfg = c.load_cfg(fn)

    # Preload any file indices
    for tup in cfg["files"]:
        d = tup[1]["path"]
        fn = d + ".idx"
        if os.access(fn, os.R_OK):
            tup[1]["_index"] = utils.load_index(fn)
    return cfg

# Root of our app server
class App(chore.server.Server, Authen_Server_mixin):

    def __init__(self, config):
	# Let Chore handle most things

Changes to utils.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19















#
# utils.py
#	Various utilities
#
import threading, string

# A "with" serialization mechanism
class Exclusion(object):
    def __init__(self):
	self.mutex = threading.Lock()
    def __enter__(self):
	self.mutex.acquire()
    def __exit__(self, typ, val, traceback):
	self.mutex.release()

# Filter out to just simple ASCII chars
def toascii(s):
    return str(filter(lambda c: c in string.printable, s))




















|














>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#
# utils.py
#	Various utilities
#
import threading, string, os

# A "with" serialization mechanism
class Exclusion(object):
    def __init__(self):
	self.mutex = threading.Lock()
    def __enter__(self):
	self.mutex.acquire()
    def __exit__(self, typ, val, traceback):
	self.mutex.release()

# Filter out to just simple ASCII chars
def toascii(s):
    return str(filter(lambda c: c in string.printable, s))

# Load file index into memory
# This should be a flat text file, sorted, which we will use
#  to provide search
# Return (file-name, cur-st_mtime, ( (line, line.lower()), ...))
def load_index(fn):
    f = open(fn, 'r')

    # Ugh, we need both the original path, and the case-flattened
    #  variant for loose search matching
    idx = tuple( (l.strip(), l.strip().lower()) for l in f )
    tup = (fn, os.fstat(f.fileno()).st_mtime, idx)

    f.close()
    return tup