Skip to content

Commit

Permalink
Refactoring 7
Browse files Browse the repository at this point in the history
Signed-off-by: Armin Wieser <armin.wieser@gmail.com>
  • Loading branch information
awieser committed Dec 28, 2011
1 parent e75821b commit dbf32be
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 183 deletions.
17 changes: 8 additions & 9 deletions common/tests/orgproperty_test.py
Expand Up @@ -19,11 +19,9 @@ def test_properties_default_ctor(self):
p = OrgProperties()
properties = unicode(p).splitlines()
self.assertEqual(properties[0], u" :PROPERTIES:")
self.assertEqual(properties[1][:-24], u" :MEMACS_CREATED: [")
# this changes every time
#self.assertEqual(properties[2],
# u" :ID: 849079e99d237b31b6a2184743cf9e33929dc749")
self.assertEqual(properties[3], u" :END:")
self.assertEqual(properties[1], u" :ID: da39a3ee5e6b" + \
"4b0d3255bfef95601890afd80709")
self.assertEqual(properties[2], u" :END:")

def test_properties_with_own_created(self):
p = OrgProperties()
Expand All @@ -32,9 +30,10 @@ def test_properties_with_own_created(self):
properties = unicode(p).splitlines()

self.assertEqual(properties[0], u" :PROPERTIES:")
self.assertEqual(properties[1], u" :CREATED: <1970-01-01 Thu 00:00>")
self.assertEqual(properties[2][:-24],u" :MEMACS_CREATED: [")
self.assertEqual(properties[3], u" :ID: fede47e9f49e1b7f5c6599a6d607e9719ca98625")
self.assertEqual(properties[4], u" :END:")
self.assertEqual(properties[1], u" :CREATED: <1970-01-0" + \
"1 Thu 00:00>")
self.assertEqual(properties[2], u" :ID: fede47e9" + \
"f49e1b7f5c6599a6d607e9719ca98625")
self.assertEqual(properties[3], u" :END:")


7 changes: 5 additions & 2 deletions filenametimestamps/memacs_filenametimestamps.py
Expand Up @@ -76,7 +76,8 @@ def __ignore_dir(self, ignore_dir):
@param return: true - if ignore_dir should be ignored
false - otherwise
"""
if self._args.exclude_folder and ignore_dir in self._args.exclude_folder:
if self._args.exclude_folder and \
ignore_dir in self._args.exclude_folder:
logging.info("ignoring ignore_dir: " + ignore_dir)
return True
else:
Expand Down Expand Up @@ -124,7 +125,9 @@ def __handle_file(self, file, rootdir):
# we need optional data for hashing due it can be, that more
# than one file have the same timestamp
properties = OrgProperties(data_for_hashing=output)
self._writer.write_org_subitem(timestamp=orgdate, output=output, properties=properties)
self._writer.write_org_subitem(timestamp=orgdate,
output=output,
properties=properties)

def _main(self):
for folder in self._args.filenametimestamps_folder:
Expand Down
9 changes: 5 additions & 4 deletions filenametimestamps/tests/memacs_filenametimestamps_test.py
Expand Up @@ -42,13 +42,14 @@ def test_functional(self):

self.assertEqual(
data[0],
"** <2011-12-19 Mon 23:59:12> [[/home/armin/code/workspace/memacs/filenametimestamps/tests/tmp//2011-12-19T23.59.12_test1.txt][2011-12-19T23.59.12_test1.txt]]")
entry)
self.assertEqual(
data[1],
" :PROPERTIES:")
self.assertEqual(
data[2],
" :ID: e3b38e22498caa8812c755ec20276714a1eb1919")
# id changes because data_for_hashing = link
#self.assertEqual(
# data[2],
# " :ID: e3b38e22498caa8812c755ec20276714a1eb1919")
self.assertEqual(
data[3],
" :END:")
Expand Down
33 changes: 20 additions & 13 deletions rss/memacs_rss.py
Expand Up @@ -32,16 +32,18 @@
Attention: RSS2.0 is required
Sample Org-entries
: ** [[http://www.wikipedia.org/][link]]: Example entry
: ** <2009-09-06 Sun 18:45> [[http://www.wikipedia.org/][link]]: Example entry
: Here is some text containing an interesting description.
: :PROPERTIES:
: :LINK: [[http://www.wikipedia.org/]]
: :CREATED: <2009-09-06 Sun 18:45>
: :ID: unique string per item
: :GUID: rss guid
: :SUMMARY: Here is some text containing an interesting description.
: :ID: unique string per item
: :END:
"""
COPYRIGHT_YEAR = "2011-2012"
COPYRIGHT_AUTHORS = """Karl Voit <tools@Karl-Voit.at>,
Armin Wieser <armin.wieser@gmail.com>"""


class RssMemacs(Memacs):
Expand Down Expand Up @@ -109,9 +111,9 @@ def __get_item_data(self, item):
note = item['description']

# converting updated_parsed UTC --> LOCALTIME
updated_time_struct = OrgFormat.datetime(
timestamp = OrgFormat.datetime(
time.localtime(calendar.timegm(item['updated_parsed'])))
properties.add("created", updated_time_struct)

properties.add("guid", guid)

except KeyError:
Expand All @@ -135,7 +137,7 @@ def __get_item_data(self, item):
logging.debug("found tag: %s", tag['term'])
tags.append(tag['term'])

return output, note, properties, tags
return output, note, properties, tags, timestamp

def _main(self):
"""
Expand All @@ -153,17 +155,22 @@ def _main(self):

for item in rss.entries:
logging.debug(item)
output, note, properties, tags = self.__get_item_data(item)
self._writer.append_org_subitem(output,
note=note,
properties=properties,
tags=tags)
output, note, properties, tags, timestamp = \
self.__get_item_data(item)
self._writer.write_org_subitem(output=output,
timestamp=timestamp,
note=note,
properties=properties,
tags=tags)

if __name__ == "__main__":
memacs = RssMemacs(
prog_version=PROG_VERSION_NUMBER,
prog_version_date=PROG_VERSION_DATE,
prog_description=PROG_DESCRIPTION,
prog_short_description=PROG_SHORT_DESCRIPTION,
prog_tag=PROG_TAG)
memacs.handle_main()
prog_tag=PROG_TAG,
copyright_year=COPYRIGHT_YEAR,
copyright_authors=COPYRIGHT_AUTHORS
)
memacs.handle_main()
18 changes: 6 additions & 12 deletions rss/tests/memacs_rss_test.py
Expand Up @@ -22,12 +22,12 @@ def setUp(self):
def test_false_appending(self):
try:
memacs = RssMemacs(argv=self.argv.split())
data = memacs.test_get_entries()
except Exception, e:
memacs.test_get_entries()
except Exception:
pass

def test_all(self):
memacs = RssMemacs(argv=self.argv.split(), append=True)
memacs = RssMemacs(argv=self.argv.split())
data = memacs.test_get_entries()

# generate assertEquals :)
Expand All @@ -36,7 +36,7 @@ def test_all(self):
# (d, data[d])
self.assertEqual(
data[0],
"** [[http://www.wikipedia.org/][Example entry]]")
"** <2009-09-06 Sun 18:45> [[http://www.wikipedia.org/][Example entry]]")
self.assertEqual(
data[1],
" Here is some text containing an interesting description.")
Expand All @@ -48,13 +48,7 @@ def test_all(self):
" :GUID: unique string per item")
self.assertEqual(
data[4],
" :CREATED: <2009-09-06 Sun 18:45>")
# self.assertEqual(
# data[5],
# " :MEMACS_CREATED: [2011-12-28 Wed 18:50:42]")
" :ID: 7ec7b2ec7d1ac5f18188352551b04f061af81e04")
self.assertEqual(
data[6],
" :ID: af9b90163e9e4727b21e8a6b452c9529a438f314")
self.assertEqual(
data[7],
data[5],
" :END:")
27 changes: 16 additions & 11 deletions versioning_systems/memacs_git.py
Expand Up @@ -28,7 +28,9 @@
If outputfile is specified, only non-existing commits are appended
"""

COPYRIGHT_YEAR = "2011-2012"
COPYRIGHT_AUTHORS = """Karl Voit <tools@Karl-Voit.at>,
Armin Wieser <armin.wieser@gmail.com>"""

class Commit(object):
"""
Expand All @@ -42,11 +44,11 @@ def __init__(self):
self.__empty = True
self.__subject = ""
self.__body = ""
self.__datetime = ""
self.__timestamp = ""
self.__author = ""
self.__properties = OrgProperties()

def __set_created(self, line):
def __set_author_timestamp(self, line):
"""
extracts the date + time from line:
author Forename Lastname <mail> 1234567890 +0000
Expand All @@ -56,17 +58,16 @@ def __set_created(self, line):
date_info = line[-16:] # 1234567890 +0000
seconds_since_epoch = float(date_info[:10])
#timezone_info = date_info[11:]
self.__datetime = OrgFormat.datetime(
self.__timestamp = OrgFormat.datetime(
time.localtime(seconds_since_epoch))
self.__author = line[7:line.find("<")].strip()
self.__properties.add("CREATED", self.__datetime)

def add_header(self, line):
"""
adds line to the header
if line contains "author" this method
calls self.__set_created(line)
calls self.__set_author_timestamp(line)
for setting right author + datetime created
every line will be added as property
Expand All @@ -85,7 +86,7 @@ def add_header(self, line):
self.__properties.add(tag, value)

if tag == "AUTHOR":
self.__set_created(line)
self.__set_author_timestamp(line)

def add_body(self, line):
"""
Expand Down Expand Up @@ -116,7 +117,8 @@ def get_output(self):
@return tupel: output,properties,body for Orgwriter.write_sub_item()
"""
output = self.__author + ": " + self.__subject
return output, self.__properties, self.__body, self.__author
return output, self.__properties, self.__body, self.__author, \
self.__timestamp


class GitMemacs(Memacs):
Expand Down Expand Up @@ -213,14 +215,15 @@ def _main(self):

# time to write all commits to org-file
for commit in commits:
output, properties, note, author = commit.get_output()
output, properties, note, author, timestamp = commit.get_output()

if not(self._args.grepuser) or \
(self._args.grepuser and self._args.grepuser == author):
# only write to stream if
# * grepuser is not set or
# * grepuser is set and we got an entry with the right author
self._writer.append_org_subitem(output=output,
self._writer.write_org_subitem(output=output,
timestamp=timestamp,
properties=properties,
note=note)

Expand All @@ -234,5 +237,7 @@ def _main(self):
prog_description=PROG_DESCRIPTION,
prog_short_description=PROG_SHORT_DESCRIPTION,
prog_tag=PROG_TAG,
append=True)
copyright_year=COPYRIGHT_YEAR,
copyright_authors=COPYRIGHT_AUTHORS
)
memacs.handle_main()
23 changes: 12 additions & 11 deletions versioning_systems/memacs_svn.py
Expand Up @@ -35,11 +35,10 @@
Then an Org-mode file is generated that contains information
about the log messages, author, and revision
New log messages are appended. Those are identified with the
:ID: property
"""

COPYRIGHT_YEAR = "2011-2012"
COPYRIGHT_AUTHORS = """Karl Voit <tools@Karl-Voit.at>,
Armin Wieser <armin.wieser@gmail.com>"""

class SvnSaxHandler(xml.sax.handler.ContentHandler):
"""
Expand Down Expand Up @@ -102,16 +101,16 @@ def __write(self):

output = "%s (r%d): %s" % (self.__author, self.__rev, subject)

properties = OrgProperties()
dt = OrgFormat.datetime(OrgFormat.datetupelutctimestamp(self.__date))
properties.add("CREATED", dt)
properties = OrgProperties(data_for_hashing=self.__author + subject)
timestamp = OrgFormat.datetime(OrgFormat.datetupelutctimestamp(self.__date))
properties.add("REVISION", self.__rev)

if self.__grepauthor == None or \
(self.__author.strip() == self.__grepauthor.strip()):
self._writer.append_org_subitem(output=output,
note=notes,
properties=properties)
self._writer.write_org_subitem(output=output,
timestamp=timestamp,
note=notes,
properties=properties)

def characters(self, content):
"""
Expand Down Expand Up @@ -218,5 +217,7 @@ def _main(self):
prog_description=PROG_DESCRIPTION,
prog_short_description=PROG_SHORT_DESCRIPTION,
prog_tag=PROG_TAG,
append=True)
copyright_year=COPYRIGHT_YEAR,
copyright_authors=COPYRIGHT_AUTHORS
)
memacs.handle_main()

0 comments on commit dbf32be

Please sign in to comment.