2 ###########################################################################
3 # Copyright (C) 2007 by Andrew Mahone
4 # <andrew.mahone@gmail.com>
6 # Copyright: See COPYING file that comes with this distribution
8 ###########################################################################
9 """support modules for scraping and viewing webcomics"""
10 import sys
, os
.path
, yaml
, re
, sqlobject
, socket
24 if hasattr(yaml
,'CSafeDumper'):
25 Dumper
= yaml
.CSafeDumper
27 Dumper
= yaml
.SafeDumper
29 if hasattr(yaml
,'CSafeLoader'):
30 Loader
= yaml
.CSafeLoader
32 Loader
= yaml
.SafeLoader
34 class ComicLoader(Loader
): pass
36 ComicLoader
.add_constructor('!re', lambda x
,y
: re
.compile(x
.construct_scalar(y
)))
38 if sys
.platform
[:3].lower() == 'win':
40 AppDir
= os
.path
.join(os
.getenv('APPDATA') or os
.getcwd(), 'comic-get')
41 SysAppDir
= os
.path
.join(os
.getenv('PROGRAMFILES'), 'comic_get')
42 SysConfDir
= SysAppDir
45 AppDir
= os
.path
.join(os
.getenv('HOME') or os
.getcwd(), '.comic_get')
46 SysAppDir
= os
.path
.join('/usr/share', 'comic_get')
47 SysConfDir
= os
.path
.join('/etc', 'comic_get')
55 from Comic
import Config
56 cdb
= os
.path
.abspath(os
.path
.join(AppDir
,'comics.db'))
58 cdb
= cdb
.replace('\\','/').replace(':','|',1)
59 cdb
= 'sqlite:/' + cdb
61 cdb
= 'sqlite://' + cdb
64 DefConfig
= Config
.Config(
65 comic_store
=os
.path
.join(AppDir
,'comics'),
66 session_store
=os
.path
.join(AppDir
,'sessions'),
75 SysConfigFile
= os
.path
.join(SysConfDir
, 'config.yml')
76 UsrConfigFile
= os
.path
.join(AppDir
, 'config.yml')
77 if not os
.path
.isdir(AppDir
):
79 Conf
= Config
.Config()
80 Conf
.update(DefConfig
)
81 Conf
.update(Config
.Config(SysConfigFile
))
82 Conf
.update(UsrConfigFile
)
85 Conf
._parent
._parent
._save
(UsrConfigFile
)
86 if 'sock_timeout' in Conf
:
87 socket
.setdefaulttimeout(Conf
.sock_timeout
)
91 DB
.SetThreadConnection()
99 obj
.createTable(ifNotExists
=True)