Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
Create git repository with the generated commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxu committed Dec 28, 2011
1 parent b5d7465 commit b3f7580
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions dokuwiki2git
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fnmatch
import logging
import os
import subprocess
import sys

USAGE = """
Expand All @@ -24,6 +25,19 @@ class Converter:
self.metadir = None
self.changelog = [] # (timestamp, ip, changetype, pagename, author, comment)
self.commands = [] # commands to run to create the git repository
self.gitdir = 'gitdir'

def create_git_repository(self):
origdir = os.getcwd()
os.mkdir(self.gitdir)
os.chdir(self.gitdir)
# run all commands
for c in self.commands:
log.debug('CMD: %s' % c)
ret = subprocess.call(c, shell=True)
if ret != 0:
raise RuntimeError('Command "%s" failed' % c)
os.chdir(origdir)

def get_pagepath_and_timestamp(self, filename):
filename = os.path.relpath(filename, self.atticdir)
Expand Down Expand Up @@ -53,15 +67,21 @@ class Converter:
pagepath, timestamp = self.get_pagepath_and_timestamp(filename)
pagefile = pagepath + '.txt'
message = c[5]
author = c[4] + '@' + c[1]
user = c[4]
if len(user) == 0:
user = 'dokuwiki2git'
author = '%s <dokuwiki@%s>' % (user, c[1])
cmds = []
if c[2] in ('C', 'E', 'e'): # create, edit, minor edit
dirname = os.path.dirname(pagefile)
if len(dirname) > 0:
cmds.append('mkdir -p "%s"' % dirname)
cmds.append('gunzip -c "%s" > "%s"' % (filename, pagefile))
cmds.append('git add "%s"' % pagefile)
elif c[2] == 'D': # delete
cmds.append('git rm "%s"' % pagefile)
cmds.append('git commit --author="%s" -m "%s"' % (author, message))
print cmds
cmds.append('git commit --allow-empty-message --author="%s" -m "%s"' % (author, message.replace('"', '\\"')))
#print cmds
self.commands.extend(cmds)

# check that all pages in attic have a matching changelog entry
Expand All @@ -88,6 +108,8 @@ class Converter:
self.commands.append('git commit --allow-empty --author="dokuwiki2git" -m "Dokuwiki data imported by dokuwiki2git"')
log.info('%d commands queud to be executed' % len(self.commands))
# TODO create the git repository, and execute commands
#print '\n'.join(self.commands)
self.create_git_repository()

def read_meta(self):
log.debug('Reading meta')
Expand Down

0 comments on commit b3f7580

Please sign in to comment.