From 7028dcb5fe31ccf6d348dca315154d719f3c481e Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 11 Oct 2007 01:27:08 +0000 Subject: [PATCH] No need to split bookmark.href - a robot will split it itself. git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@83 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23 --- Robots/bkmk_rforking.py | 4 ++-- Robots/bkmk_rforking_sub.py | 9 ++++----- Robots/bkmk_rsimple.py | 3 ++- Robots/bkmk_rsimple_tos.py | 4 ++-- bkmk-add.py | 7 +++---- bkmk_objects.py | 7 +++++++ check_urls.py | 11 +++++------ 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Robots/bkmk_rforking.py b/Robots/bkmk_rforking.py index 1fb18a0..4693f52 100644 --- a/Robots/bkmk_rforking.py +++ b/Robots/bkmk_rforking.py @@ -1,7 +1,7 @@ """ Forking robot - Written by BroytMann. Copyright (C) 2000-2007 PhiloSoft Design + Written by BroytMann. Copyright (C) 2000-2007 PhiloSoft Design. """ @@ -36,7 +36,7 @@ def restart_subp(log): from bkmk_objects import Robot class robot_forking(Robot): - def check_url(self, bookmark, url_type, url_rest): + def check_url(self, bookmark): if not check_subp: restart_subp(self.log) # Not restart, just start afresh diff --git a/Robots/bkmk_rforking_sub.py b/Robots/bkmk_rforking_sub.py index 91460f3..6ae0d8c 100755 --- a/Robots/bkmk_rforking_sub.py +++ b/Robots/bkmk_rforking_sub.py @@ -1,12 +1,12 @@ #! /usr/bin/env python """ - Check URL - subprocess + Check URL - subprocess for the forking robot - Written by BroytMann, Mar 1999 - Aug 2002. Copyright (C) 1999-2002 PhiloSoft Design + Written by BroytMann. Copyright (C) 1999-2007 PhiloSoft Design. """ -import sys, os, urllib +import sys, os lib_dir = os.path.normpath(os.path.dirname(sys.argv[0]) + os.sep + os.pardir) sys.path.append(lib_dir) # for bkmk_objects.py @@ -33,8 +33,7 @@ def run(): while 1: bookmark = pickle.loads(bkmk_in.read_record()) log(bookmark.href) - url_type, url_rest = urllib.splittype(bookmark.href) - robot.check_url(bookmark, url_type, url_rest) + robot.check_url(bookmark) bkmk_out.write_record(pickle.dumps(bookmark)) log.outfile.flush() diff --git a/Robots/bkmk_rsimple.py b/Robots/bkmk_rsimple.py index 58879b0..1c4795c 100644 --- a/Robots/bkmk_rsimple.py +++ b/Robots/bkmk_rsimple.py @@ -83,13 +83,14 @@ from bkmk_objects import Robot from parse_html import parse_html class robot_simple(Robot): - def check_url(self, bookmark, url_type, url_rest): + def check_url(self, bookmark): if not self.tempfname: self.tempfname = bookmark.tempfname try: try: self.start = int(time.time()) + url_type, url_rest = urllib.splittype(bookmark.href) url_host, url_path = urllib.splithost(url_rest) url_path, url_tag = urllib.splittag(url_path) diff --git a/Robots/bkmk_rsimple_tos.py b/Robots/bkmk_rsimple_tos.py index cecb515..b7e89e8 100644 --- a/Robots/bkmk_rsimple_tos.py +++ b/Robots/bkmk_rsimple_tos.py @@ -11,9 +11,9 @@ timeoutsocket.setDefaultSocketTimeout(900) from bkmk_rsimple import robot_simple, get_error class robot_simple_tos(robot_simple): - def check_url(self, bookmark, url_type, url_rest): + def check_url(self, bookmark): try: - return robot_simple.check_url(self, bookmark, url_type, url_rest) + return robot_simple.check_url(self, bookmark) except (socket.error, timeoutsocket.Timeout), msg: bookmark.error = get_error(msg) diff --git a/bkmk-add.py b/bkmk-add.py index 24952ce..6bd02c5 100755 --- a/bkmk-add.py +++ b/bkmk-add.py @@ -2,11 +2,11 @@ """ Add a bookmark to the database. - Written by BroytMann, Aug 2002. Copyright (C) 2002 PhiloSoft Design + Written by BroytMann. Copyright (C) 2002-2007 PhiloSoft Design. """ -import sys, os, time, urllib +import sys, os, time from bkmk_objects import Bookmark from Robots.bkmk_rsimple import robot_simple @@ -54,9 +54,8 @@ def run(): bookmark.name = '' robot = robot_simple(tempfname, None) - url_type, url_rest = urllib.splittype(href) - if robot.check_url(bookmark, url_type, url_rest): # get real title and last modified date + if robot.check_url(bookmark): # get real title and last modified date if title: # forced title bookmark.name = title elif hasattr(bookmark, "real_title"): diff --git a/bkmk_objects.py b/bkmk_objects.py index 584b87f..344312c 100644 --- a/bkmk_objects.py +++ b/bkmk_objects.py @@ -159,3 +159,10 @@ def make_tree(linear): object.parent.append(object) return root_folder + +def break_tree(linear): + root_folder = linear[0] + del linear[0] + + for object in linear: + del object.parent diff --git a/check_urls.py b/check_urls.py index 75f3155..4081637 100755 --- a/check_urls.py +++ b/check_urls.py @@ -2,11 +2,11 @@ """ Robot interface - check URLs from bookmarks database - Written by BroytMann, Mar 2000 - Aug 2002. Copyright (C) 2000-2002 PhiloSoft Design + Written by BroytMann. Copyright (C) 2000-2007 PhiloSoft Design. """ -import sys, os, urllib, tempfile +import sys, os, tempfile tempfname = "check_urls" + tempfile.gettempprefix() + "tmp" @@ -31,7 +31,7 @@ def run(): pass if report_stats: - print "BroytMann check_urls, Copyright (C) 1997-2002 PhiloSoft Design" + print "BroytMann check_urls, Copyright (C) 1997-2007 PhiloSoft Design" if args: sys.stderr.write("check_urls: too many arguments\n") @@ -118,9 +118,8 @@ def run(): if hasattr(old_object, attr_name): setattr(object, attr_name, getattr(old_object, attr_name)) else: - url_type, url_rest = urllib.splittype(object.href) - log("Checking %s:%s" % (url_type, url_rest)) - rcode = robot.check_url(object, url_type, url_rest) + log("Checking %s" % object.href) + rcode = robot.check_url(object) if rcode: checked[object.href] = object_no -- 2.39.5