Merge branch 'kirbybase' into develop
This commit is contained in:
commit
b5aac62357
9 changed files with 2129 additions and 33 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
\#*\#
|
\#*\#
|
||||||
.*
|
.*
|
||||||
|
modules/plane.tbl
|
6
4grab.py
6
4grab.py
|
@ -24,16 +24,12 @@ import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
from util import raw_input_with_default
|
||||||
|
|
||||||
import download
|
import download
|
||||||
import progressbar
|
import progressbar
|
||||||
import sorter
|
import sorter
|
||||||
|
|
||||||
def raw_input_with_default(default, prompt):
|
|
||||||
inp = raw_input("%s (default=%s): " % (prompt, default))
|
|
||||||
if inp == "":
|
|
||||||
return default
|
|
||||||
return inp
|
|
||||||
config._optioncreator = raw_input_with_default
|
config._optioncreator = raw_input_with_default
|
||||||
|
|
||||||
base_url = "http://boards.4chan.org/"
|
base_url = "http://boards.4chan.org/"
|
||||||
|
|
60
backend.py
Normal file
60
backend.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import os
|
||||||
|
import modules.kirbybase
|
||||||
|
from util import confdir,raw_input_with_default
|
||||||
|
import config
|
||||||
|
|
||||||
|
class _Backend(object):
|
||||||
|
""" A class that communicates with the datastore """
|
||||||
|
def __init__(self):
|
||||||
|
self.table = os.path.join(confdir, "images.tbl")
|
||||||
|
self.store = modules.kirbybase.KirbyBase()
|
||||||
|
self.__collection = ""
|
||||||
|
self.__new_collection = []
|
||||||
|
|
||||||
|
self.load()
|
||||||
|
|
||||||
|
def create_store_if_needed(self):
|
||||||
|
if not os.path.exists(self.table):
|
||||||
|
return self.store.create(self.table, ["filename:String"])
|
||||||
|
return True
|
||||||
|
|
||||||
|
def add(self, filename):
|
||||||
|
self.__new_collection.append(filename)
|
||||||
|
|
||||||
|
def check(self, filename):
|
||||||
|
collected = filename in self.__collection
|
||||||
|
downloaded = filename in self.__new_collection
|
||||||
|
|
||||||
|
if not downloaded:
|
||||||
|
self.add(filename)
|
||||||
|
|
||||||
|
if collected or downloaded:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
os.remove(self.table)
|
||||||
|
self.create_store_if_needed()
|
||||||
|
for f in self.__new_collection:
|
||||||
|
self.store.insert(self.table, [f])
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
if os.path.exists(self.table):
|
||||||
|
self.__collection = self.store.select(self.table, ['recno'], ['*'], ['filename'], returnType="report")
|
||||||
|
|
||||||
|
_backend = None
|
||||||
|
def Backend():
|
||||||
|
global _backend
|
||||||
|
|
||||||
|
if _backend == None:
|
||||||
|
_backend = _Backend()
|
||||||
|
return _backend
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
backend = Backend()
|
||||||
|
config._optioncreator = raw_input_with_default
|
||||||
|
cfg = config.Configuration()
|
||||||
|
|
||||||
|
for f in os.listdir(cfg.get_archive_location()):
|
||||||
|
backend.add(f)
|
|
@ -20,15 +20,11 @@
|
||||||
import os
|
import os
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import sys
|
import sys
|
||||||
|
from util import homedir, confdir
|
||||||
# Get our reference point. preferably $HOME.
|
|
||||||
homedir = os.getenv("HOME")
|
|
||||||
if homedir is None:
|
|
||||||
homedir = os.path.dirname(sys.argv[0])
|
|
||||||
|
|
||||||
class _Configuration(object):
|
class _Configuration(object):
|
||||||
def __init__(self, optioncreator):
|
def __init__(self, optioncreator):
|
||||||
self.filename = os.path.join(os.path.join(homedir, ".4grab"), "config.cfg")
|
self.filename = os.path.join(confdir, "config.cfg")
|
||||||
self.configparser = ConfigParser.RawConfigParser()
|
self.configparser = ConfigParser.RawConfigParser()
|
||||||
self.optioncreator = optioncreator
|
self.optioncreator = optioncreator
|
||||||
|
|
||||||
|
|
13
download.py
13
download.py
|
@ -22,6 +22,7 @@ import os
|
||||||
import htmlparser
|
import htmlparser
|
||||||
import config
|
import config
|
||||||
import sys
|
import sys
|
||||||
|
import backend
|
||||||
|
|
||||||
def get_savedir():
|
def get_savedir():
|
||||||
conf = config.Configuration()
|
conf = config.Configuration()
|
||||||
|
@ -30,12 +31,10 @@ def get_savedir():
|
||||||
os.makedirs(savedir)
|
os.makedirs(savedir)
|
||||||
return savedir
|
return savedir
|
||||||
def check_archive(fullpath):
|
def check_archive(fullpath):
|
||||||
conf = config.Configuration()
|
|
||||||
archive = conf.get_archive_location()
|
|
||||||
filename = os.path.basename(fullpath)
|
filename = os.path.basename(fullpath)
|
||||||
archfile = os.path.join(archive, filename)
|
be = backend.Backend()
|
||||||
#sys.stderr.write("%s %d\n" % (archfile, os.path.exists(archfile)))
|
return be.check(filename)
|
||||||
return os.path.exists(archfile)
|
|
||||||
def write(message):
|
def write(message):
|
||||||
sys.stdout.write(message)
|
sys.stdout.write(message)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
@ -145,6 +144,10 @@ class Downloader(object):
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
progress.complete()
|
progress.complete()
|
||||||
|
|
||||||
|
be = backend.Backend()
|
||||||
|
be.save()
|
||||||
|
|
||||||
return (skipped, failed, downloaded, total)
|
return (skipped, failed, downloaded, total)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
0
modules/__init__.py
Normal file
0
modules/__init__.py
Normal file
2035
modules/kirbybase.py
Normal file
2035
modules/kirbybase.py
Normal file
File diff suppressed because it is too large
Load diff
20
sorter.py
20
sorter.py
|
@ -22,6 +22,7 @@ import Image
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
|
import backend
|
||||||
|
|
||||||
def dummy_option_creator(value1, value2): pass
|
def dummy_option_creator(value1, value2): pass
|
||||||
config._optioncreator = dummy_option_creator
|
config._optioncreator = dummy_option_creator
|
||||||
|
@ -36,7 +37,7 @@ class Sorter:
|
||||||
download_base = self.conf.get_download_location()
|
download_base = self.conf.get_download_location()
|
||||||
retval = True
|
retval = True
|
||||||
|
|
||||||
if self.check_filename(filename):
|
if not self.check_filename(filename):
|
||||||
image = None
|
image = None
|
||||||
try:
|
try:
|
||||||
image = Image.open(os.path.join(download_base,
|
image = Image.open(os.path.join(download_base,
|
||||||
|
@ -59,7 +60,6 @@ class Sorter:
|
||||||
|
|
||||||
self.copy(filename, folderpath)
|
self.copy(filename, folderpath)
|
||||||
break
|
break
|
||||||
|
|
||||||
self.archive(filename)
|
self.archive(filename)
|
||||||
self.remove(filename)
|
self.remove(filename)
|
||||||
return retval
|
return retval
|
||||||
|
@ -84,20 +84,12 @@ class Sorter:
|
||||||
print "\nHow can this even happen?! Copying", source, "to", dest
|
print "\nHow can this even happen?! Copying", source, "to", dest
|
||||||
|
|
||||||
def archive(self, filename):
|
def archive(self, filename):
|
||||||
location = self.conf.get_archive_location()
|
be = backend.Backend()
|
||||||
if not os.path.exists(location):
|
be.add(os.path.basename(filename))
|
||||||
os.makedirs(location)
|
|
||||||
|
|
||||||
dest = os.path.join(location, os.path.basename(filename))
|
|
||||||
#print dest
|
|
||||||
f = open(dest, "w")
|
|
||||||
file.close(f)
|
|
||||||
|
|
||||||
|
|
||||||
def archive_check(self, filename):
|
def archive_check(self, filename):
|
||||||
archive_path = self.conf.get_archive_location()
|
be = backend.Backend()
|
||||||
fullname = os.path.join(archive_path, filename)
|
return be.check(os.path.basename(filename))
|
||||||
return os.path.exists(fullname)
|
|
||||||
|
|
||||||
def check_filename(self, filename):
|
def check_filename(self, filename):
|
||||||
ext = os.path.splitext(filename)[1]
|
ext = os.path.splitext(filename)[1]
|
||||||
|
|
13
util.py
Normal file
13
util.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
homedir = os.getenv("HOME")
|
||||||
|
if homedir is None:
|
||||||
|
homedir = os.path.dirname(sys.argv[0])
|
||||||
|
confdir = os.path.join(homedir, ".4grab")
|
||||||
|
|
||||||
|
def raw_input_with_default(default, prompt):
|
||||||
|
inp = raw_input("%s (default=%s): " % (prompt, default))
|
||||||
|
if inp == "":
|
||||||
|
return default
|
||||||
|
return inp
|
Loading…
Reference in a new issue