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
|
||||
\#*\#
|
||||
.*
|
||||
modules/plane.tbl
|
6
4grab.py
6
4grab.py
|
@ -24,16 +24,12 @@ import sys
|
|||
import os
|
||||
|
||||
import config
|
||||
from util import raw_input_with_default
|
||||
|
||||
import download
|
||||
import progressbar
|
||||
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
|
||||
|
||||
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 ConfigParser
|
||||
import sys
|
||||
|
||||
# Get our reference point. preferably $HOME.
|
||||
homedir = os.getenv("HOME")
|
||||
if homedir is None:
|
||||
homedir = os.path.dirname(sys.argv[0])
|
||||
from util import homedir, confdir
|
||||
|
||||
class _Configuration(object):
|
||||
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.optioncreator = optioncreator
|
||||
|
||||
|
|
13
download.py
13
download.py
|
@ -22,6 +22,7 @@ import os
|
|||
import htmlparser
|
||||
import config
|
||||
import sys
|
||||
import backend
|
||||
|
||||
def get_savedir():
|
||||
conf = config.Configuration()
|
||||
|
@ -30,12 +31,10 @@ def get_savedir():
|
|||
os.makedirs(savedir)
|
||||
return savedir
|
||||
def check_archive(fullpath):
|
||||
conf = config.Configuration()
|
||||
archive = conf.get_archive_location()
|
||||
filename = os.path.basename(fullpath)
|
||||
archfile = os.path.join(archive, filename)
|
||||
#sys.stderr.write("%s %d\n" % (archfile, os.path.exists(archfile)))
|
||||
return os.path.exists(archfile)
|
||||
be = backend.Backend()
|
||||
return be.check(filename)
|
||||
|
||||
def write(message):
|
||||
sys.stdout.write(message)
|
||||
sys.stdout.flush()
|
||||
|
@ -145,6 +144,10 @@ class Downloader(object):
|
|||
i += 1
|
||||
|
||||
progress.complete()
|
||||
|
||||
be = backend.Backend()
|
||||
be.save()
|
||||
|
||||
return (skipped, failed, downloaded, total)
|
||||
|
||||
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 os
|
||||
import datetime
|
||||
import backend
|
||||
|
||||
def dummy_option_creator(value1, value2): pass
|
||||
config._optioncreator = dummy_option_creator
|
||||
|
@ -36,7 +37,7 @@ class Sorter:
|
|||
download_base = self.conf.get_download_location()
|
||||
retval = True
|
||||
|
||||
if self.check_filename(filename):
|
||||
if not self.check_filename(filename):
|
||||
image = None
|
||||
try:
|
||||
image = Image.open(os.path.join(download_base,
|
||||
|
@ -59,7 +60,6 @@ class Sorter:
|
|||
|
||||
self.copy(filename, folderpath)
|
||||
break
|
||||
|
||||
self.archive(filename)
|
||||
self.remove(filename)
|
||||
return retval
|
||||
|
@ -84,20 +84,12 @@ class Sorter:
|
|||
print "\nHow can this even happen?! Copying", source, "to", dest
|
||||
|
||||
def archive(self, filename):
|
||||
location = self.conf.get_archive_location()
|
||||
if not os.path.exists(location):
|
||||
os.makedirs(location)
|
||||
|
||||
dest = os.path.join(location, os.path.basename(filename))
|
||||
#print dest
|
||||
f = open(dest, "w")
|
||||
file.close(f)
|
||||
|
||||
be = backend.Backend()
|
||||
be.add(os.path.basename(filename))
|
||||
|
||||
def archive_check(self, filename):
|
||||
archive_path = self.conf.get_archive_location()
|
||||
fullname = os.path.join(archive_path, filename)
|
||||
return os.path.exists(fullname)
|
||||
be = backend.Backend()
|
||||
return be.check(os.path.basename(filename))
|
||||
|
||||
def check_filename(self, filename):
|
||||
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