Skip to content

Commit

Permalink
WIP: python3
Browse files Browse the repository at this point in the history
Harvest/hachoir-core/metadata not python3 compatible
  • Loading branch information
reinhardt committed Oct 24, 2019
1 parent eaf8759 commit be7951e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions bulk_change_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from harvest import Harvest
from octodon import get_config
from pprint import pprint
from functools import reduce


def harvest_date_range(startdate, enddate):
Expand Down
43 changes: 24 additions & 19 deletions octodon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
from cmd import Cmd
from datetime import datetime, timedelta
from ConfigParser import SafeConfigParser
from configparser import ConfigParser
import argparse
import subprocess
from tempfile import NamedTemporaryFile
Expand All @@ -16,6 +16,7 @@
from pyactiveresource.activeresource import ActiveResource
from pyactiveresource.connection import ResourceNotFound
from pyactiveresource import connection
from functools import reduce


ticket_pattern = re.compile('#([A-Z0-9-]+)')
Expand Down Expand Up @@ -161,33 +162,38 @@ def format_spent_time(time):


def pad(string, length):
return string + ' ' * (length - len(string.decode('utf-8')))
return string + ' ' * (length - len(string))


def make_row(entry, activities):
act_name = entry['activity']
return ['1',
entry['description'].encode('utf-8'),
entry['description'],
format_spent_time(entry['time']),
act_name.encode('utf-8'),
act_name,
entry['issue_id'] or '',
entry['project'].encode('utf-8'),
entry['comments'].encode('utf-8'),
entry['project'],
entry['comments'],
]


def make_table(rows):
rows = [['L', 'Headline', 'Time', 'Activity', 'iss', 'Project', 'Comments']] + rows
columns = zip(*rows)
max_lens = [max([len(entry.decode('utf-8')) for entry in column]) for column in columns]
max_lens = [max([len(entry) for entry in column]) for column in columns]
out_strs = []
divider = '+%s+' % '+'.join(
['-' * (max_len + 2) for max_len in max_lens]
)
for row in rows:
vals = []
for i in range(len(row)):
vals.append(' %s ' % pad(row[i].replace('|', ' '), max_lens[i]))
vals.append(
' %s ' % pad(
row[i].replace('|', ' '),
max_lens[i],
)
)
row_str = '|%s|' % '|'.join(vals)
out_strs.append(divider)
out_strs.append(row_str)
Expand Down Expand Up @@ -235,15 +241,13 @@ def write_to_file(bookings, spent_on, activities, file_name=None):

def read_from_file(filename, activities):
tmpfile = open(filename, 'r')
data = tmpfile.readlines()
tmpfile.close()
bookings = []
spentdate = None
default_activity = get_default_activity(activities)
default_act_name = default_activity.get('name', '[noname]')
default_columns = [1, '', '0:0', default_act_name, -1, '', '']

for line in data:
for line in tmpfile:
if line.startswith('Clock summary at ['):
splitdate = line[18:-2].split(' ')[0].split('-')
spentdate = datetime(int(splitdate[0]),
Expand All @@ -261,11 +265,12 @@ def read_from_file(filename, activities):
bookings.append({'issue_id': columns[4],
'spent_on': spentdate.strftime('%Y-%m-%d'),
'time': float(spenttime),
'comments': columns[6].decode('utf-8'),
'project': columns[5].decode('utf-8'),
'description': columns[1].decode('utf-8'),
'activity': columns[3].decode('utf-8'),
'comments': columns[6],
'project': columns[5],
'description': columns[1],
'activity': columns[3],
})
tmpfile.close()
return spentdate, bookings


Expand Down Expand Up @@ -555,7 +560,7 @@ def get_harvest_target(self, entry):
elif self.redmine:
pid = issue['project']['id']
try:
project = self.redmine.Projects.get(pid)['identifier'].decode('utf-8')
project = self.redmine.Projects.get(pid)['identifier']
except Exception as e:
print('Could not get project identifier: {0}; {1}'.format(
issue['project']['name'], e))
Expand All @@ -565,7 +570,7 @@ def get_harvest_target(self, entry):

for tag in entry['tags']:
if tag in harvest_projects:
project = tag.decode('utf-8')
project = tag
if entry['category'] in harvest_projects:
project = entry['category']

Expand Down Expand Up @@ -831,10 +836,10 @@ def do_EOF(self, line):


def get_config(cfgfile):
config = SafeConfigParser()
config = ConfigParser()
default_cfgfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'defaults.cfg')
config.readfp(open(default_cfgfile))
config.read_file(open(default_cfgfile))

editor = os.environ.get('EDITOR')
if editor:
Expand Down

0 comments on commit be7951e

Please sign in to comment.