Commits

Ruy Adorno committed 6bf1feb

* Fixed some issues with getting attributes from add time method

  • Participants
  • Parent commits 4e78054

Comments (0)

Files changed (1)

     f.close()
     return options
 
-class Jazz:
-
-    def __init__(self):
-        self.parse_config_file()
-        self.start_parser()
-        self.parse_arguments()
-        self.start_redmine()
-        self.parse_subcommands()
-
-    def parse_config_file(self):
-        try:
-            options = parse_config()
-            self.redmineurl = options['url']
-            self.redminekey = getattr(options, 'key', None)
-            self.redmineuser = getattr(options, 'username', None)
-            self.redminepass = getattr(options, 'password', None)
-            self.default_project = getattr(options, 'project', None)
-            self.default_activity = getattr(options, 'activity', None)
-            self.default_message = getattr(options, 'message', None)
-            self.no_config_file = False
-        except IOError:
-            self.no_config_file = True
-            print "No configuration file found at: "+os.path.expanduser(DEFAULT_CONFIG_FILE)
-
-    def start_redmine(self):
-        try:
-            if self.redminekey:
-                self.redmine = Redmine(self.redmineurl, self.redminekey)
-            else:
-                self.redmine = Redmine(self.redmineurl, username=self.redmineuser, password=self.redminepass)
-                
-        except URLError:
-            print "ERROR: Can't connect to server, check if the redmine URL is correct"
-            self.parser.exit()
-
-    def start_parser(self):
-        self.parser = ArgumentParser(description="Provides a basic interface to access redmine.", prog="jazz")
-        self.parser.add_argument("-u", "--url", help="Redmine url")
-        self.parser.add_argument("-k", "--key", help="Your user key")
-        self.subparsers = self.parser.add_subparsers(help="Available commands:")
-        self.li = self.subparsers.add_parser("li", help="List issues from redmine.")
-        self.li.add_argument("-p", "--project", help="Specify a project to get the issues.")
-        self.li.set_defaults(func=self.list_issues)
-        self.add = self.subparsers.add_parser("add", help="Create a new time entry.")
-        self.add.add_argument("-p", "--project", help="Specify a project to get the issues.")
-        self.add.add_argument("-i", "--issue", help="The id of a specific issue to add the time.")
-        self.add.add_argument("-t", "--hours", "--time", help="The amount of time spent (in hours).")
-        self.add.add_argument("-a", "--activity", help="The id of the activity")
-        self.add.add_argument("-m", "--message", help="A short description for the entry (255 chars max)")
-        self.add.set_defaults(func=self.add_time)
-        self.log = self.subparsers.add_parser("log", help="Get logged time in the system")
-        self.log.set_defaults(func=self.get_log)
-
-    def parse_arguments(self):
-        self.args = self.parser.parse_args()
-        if self.args.url:
-            self.redmineurl = self.args.url
-        if self.args.key:
-            self.redminekey = self.args.key
-        if self.no_config_file and not self.args.url and not self.args.key:
-            print "ERROR: You need to specify an redmine url and key in order to use this program"
-            self.parser.exit()
-
-    def parse_subcommands(self):
-        self.args.func(self.args)
-
-    def list_issues(self, args):
-        if not args.project:
-            self.print_issues(self.redmine.getIssues())
-        else:
-            self.print_issues(self.redmine.getProject(args.project).getIssues())
-
-    def print_issues(self, issues):
-        print "\nOpen Issues:\n"
-        for issue in issues:
-            print "Issue#: "+issue['id']+" - "+issue['subject']+" - "+issue["done_ratio"]+"% done"
-
-    def add_time(self, args):
-        print "\nAdding time:\n"
-        project_id = getattr(args, 'project', self.default_project)
-        issue_id = getattr(args, 'issue', None)
-        if not args.hours or args.time:
-            print "ERROR: You need to specify the amount of time spent!"
-            self.parser.exit()
-        hours = getattr(args, 'hours', args.time)
-        activity_id = getattr(args, 'activity', self.default_activity)
-        message = getattr(args, 'message', self.default_message)
-        self.redmine.createTimeEntry(hours, activity_id, message, issue_id, project_id)
-
-    def get_log(self, args):
-        pass
-
-#Entry point (maybe it's ugly?)
-Jazz()
-
 
 class Redmine:
     
         
         if not password:
             password = ''
-        
+
         if( username and password ):
             password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
             password_mgr.add_password(None, url, username, password )
         post_xml += "<activity_id>"+activity_id+"</activity_id>"
         post_xml += "<comments>"+comments+"</comments>"
         post_xml += "</time_entry>"
-        encoded_content = post_xml
-        return self.post("time_entries.xml", encoded_content)
+        print post_xml
+        return self.post("time_entries.xml", post_xml)
+
+class Jazz:
+
+    def __init__(self):
+        self.parse_config_file()
+        self.start_parser()
+        self.parse_arguments()
+        self.start_redmine()
+        self.parse_subcommands()
+
+    def parse_config_file(self):
+        try:
+            options = parse_config()
+            self.redmineurl = options['url']
+            self.redminekey = dict.get(options, 'key')
+            self.redmineuser = dict.get(options, 'username')
+            self.redminepass = dict.get(options, 'password')
+            self.default_project = dict.get(options, 'project')
+            self.default_activity = dict.get(options, 'activity')
+            self.default_message = dict.get(options, 'message')
+            self.no_config_file = False
+        except IOError:
+            self.no_config_file = True
+            print "No configuration file found at: "+os.path.expanduser(DEFAULT_CONFIG_FILE)
+
+    def start_redmine(self):
+        try:
+            if self.redminekey:
+                self.redmine = Redmine(self.redmineurl, self.redminekey)
+            else:
+                self.redmine = Redmine(self.redmineurl, username=self.redmineuser, password=self.redminepass)
+                
+        except URLError:
+            print "ERROR: Can't connect to server, check if the redmine URL is correct"
+            self.parser.exit()
+
+    def start_parser(self):
+        self.parser = ArgumentParser(description="Provides a basic interface to access redmine.", prog="jazz")
+        self.parser.add_argument("-u", "--url", help="Redmine url")
+        self.parser.add_argument("-k", "--key", help="Your user key")
+        self.subparsers = self.parser.add_subparsers(help="Available commands:")
+        self.li = self.subparsers.add_parser("li", help="List issues from redmine.")
+        self.li.add_argument("-p", "--project", help="Specify a project to get the issues.")
+        self.li.set_defaults(func=self.list_issues)
+        self.add = self.subparsers.add_parser("add", help="Create a new time entry.")
+        self.add.add_argument("-p", "--project", help="Specify a project to get the issues.")
+        self.add.add_argument("-i", "--issue", help="The id of a specific issue to add the time.")
+        self.add.add_argument("-t", "--hours", "--time", help="The amount of time spent (in hours).")
+        self.add.add_argument("-a", "--activity", help="The id of the activity")
+        self.add.add_argument("-m", "--message", help="A short description for the entry (255 chars max)")
+        self.add.set_defaults(func=self.add_time)
+        self.log = self.subparsers.add_parser("log", help="Get logged time in the system")
+        self.log.set_defaults(func=self.get_log)
+
+    def parse_arguments(self):
+        self.args = self.parser.parse_args()
+        if self.args.url:
+            self.redmineurl = self.args.url
+        if self.args.key:
+            self.redminekey = self.args.key
+        if self.no_config_file and not self.args.url and not self.args.key:
+            print "ERROR: You need to specify an redmine url and key in order to use this program"
+            self.parser.exit()
+
+    def parse_subcommands(self):
+        self.args.func(self.args)
+
+    def list_issues(self, args):
+        if not args.project:
+            self.print_issues(self.redmine.getIssues())
+        else:
+            self.print_issues(self.redmine.getProject(args.project).getIssues())
+
+    def print_issues(self, issues):
+        print "\nOpen Issues:\n"
+        for issue in issues:
+            print "Issue#: "+issue['id']+" - "+issue['subject']+" - "+issue["done_ratio"]+"% done"
+
+    def add_time(self, args):
+        print "\nAdding time:\n"
+        project_id = getattr(args, 'project', self.default_project)
+        issue_id = getattr(args, 'issue', None)
+        if not args.hours:
+            print "ERROR: You need to specify the amount of time spent!"
+            self.parser.exit()
+        hours = args.hours
+        activity_id = args.activity
+        if activity_id == None: activity_id = self.default_activity
+        message = args.message
+        if message == None: message = self.default_message
+        self.redmine.createTimeEntry(hours, activity_id, message, issue_id, project_id)
+
+    def get_log(self, args):
+        pass
+
+#Entry point (maybe it's ugly?)
+Jazz()
+