Permalink
Browse files

Merge branch 'master' into gitmark_web

* master:
  Preserve bookmark timestamps during Delicious import.
  Restore Windows compatibility, which my shell escaping fix would have broken.
  Log an error but save the bookmark and continue if downloading content fails
  Add each list of files in a single git command
  Fix errors due to quotes or other shell-recognized characters in description
  Show progress with percent complete during import from Delicious
  • Loading branch information...
2 parents a9556fe + b3912ba commit 51a81ebcf3e98f40f5e1223ee98ea7345c7f7849 @jcn jcn committed Dec 17, 2010
Showing with 33 additions and 13 deletions.
  1. +14 −2 delicious_import.py
  2. +19 −11 gitmark.py
View
@@ -25,7 +25,8 @@ def __init__(self, username, password=''):
x = minidom.parseString(content)
# sample post: <post href="http://www.pixelbeat.org/cmdline.html" hash="e3ac1d1e4403d077ee7e65f62a55c406" description="Linux Commands - A practical reference" tag="linux tutorial reference" time="2010-11-29T01:07:35Z" extended="" meta="c79362665abb0303d577b6b9aa341599" />
- for post in x.getElementsByTagName("post"):
+ post_list = x.getElementsByTagName('post')
+ for post_index, post in enumerate(post_list):
url = post.getAttribute('href')
desc = post.getAttribute('description')
tags = ",".join([t for t in post.getAttribute('tag').split()])
@@ -36,9 +37,20 @@ def __init__(self, username, password=''):
options['push'] = False
options['msg'] = desc
- args = [url]
+ # Set the authoring date of the commit based on the imported
+ # timestamp. git reads the GIT_AUTHOR_DATE environment var.
+ os.environ['GIT_AUTHOR_DATE'] = timestamp
+ args = [url]
g = gitMark(options, args)
+
+ # Reset authoring timestamp (abundance of caution)
+ del os.environ['GIT_AUTHOR_DATE']
+
+ if post_list.length > 1:
+ print '%d of %d bookmarks imported (%d%%)' % (
+ post_index + 1, post_list.length,
+ (post_index + 1.0) / post_list.length * 100)
if __name__ == '__main__':
View
@@ -17,6 +17,12 @@
from settings import *
+# Arguments are passed directly to git, not through the shell, to avoid the
+# need for shell escaping. On Windows, however, commands need to go through the
+# shell for git to be found on the PATH, but escaping is automatic there. So
+# send git commands through the shell on Windows, and directly everywhere else.
+USE_SHELL = os.name == 'nt'
+
class gitMark(object):
def __init__(self, options, args):
@@ -50,14 +56,10 @@ def __init__(self, options, args):
self.gitPush()
def gitAdd(self, files):
- for f in files:
- cmd = 'git add %s' % f
- pipe = subprocess.Popen(cmd, shell=True)
- pipe.wait()
-
+ subprocess.call(['git', 'add'] + files, shell=USE_SHELL)
+
def gitCommit(self, msg):
- pipe = subprocess.Popen("git commit -m '%s'" % msg, shell=True)
- pipe.wait()
+ subprocess.call(['git', 'commit', '-m', msg], shell=USE_SHELL)
def gitPush(self):
pipe = subprocess.Popen("git push origin master", shell=True)
@@ -90,9 +92,15 @@ def generateHash(self, text):
return m.hexdigest()
def getContent(self, url):
- h = urllib.urlopen(url)
- content = h.read()
- h.close()
+ try:
+ h = urllib.urlopen(url)
+ content = h.read()
+ h.close()
+ except IOError, e:
+ print >>sys.stderr, ("Error: could not retrieve the content of a"
+ " URL. The bookmark will be saved, but its content won't be"
+ " searchable. URL: <%s>. Error: %s" % (url, e))
+ content = ''
return content
@@ -106,4 +114,4 @@ def getContent(self, url):
opts = {'push': options.push, 'tags': options.tags, 'msg': options.msg}
- g = gitMark(opts, args)
+ g = gitMark(opts, args)

0 comments on commit 51a81eb

Please sign in to comment.