~ubuntu-branches/ubuntu/trusty/webservice-office-zoho/trusty

« back to all changes in this revision

Viewing changes to bin/webservice-office-zoho

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Bennett, Alexander Sack
  • Date: 2010-04-09 16:39:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100409163935-706v6jmyvrjsfgp4
Tags: 0.4.1-0ubuntu1
* debian/copyright: Add icon copyright text supplied by Zoho Corp. 

[ Alexander Sack <asac@ubuntu.com> ]
* remove debian/webservice-office-zoho.install to fix ftbfs; all is
  properly installed by setup.py anyway.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
'''Open local or online documents using the zoho web services'''
19
19
 
20
20
__author__ = 'jb@canonical.com'
21
 
__version__ = '0.1'
 
21
__version__ = '0.2'
22
22
 
23
23
import getopt
24
24
import os.path
26
26
import webbrowser
27
27
 
28
28
import pycurl
 
29
import re
29
30
 
30
31
# unique api key
31
32
apikey = '9f950e366ef183c76e5543135f05acdb'
35
36
sheetURL  = 'http://sheet.zoho.com/remotedoc.im'
36
37
showURL   = 'http://show.zoho.com/remotedoc.im'
37
38
onlineURL = 'http://viewer.zoho.com/api/view.do?url='
 
39
defaultDocURL = 'http://writer.zoho.com/home?serviceurl=%2Findex.do'
 
40
defaultSheetURL = 'http://sheet.zoho.com/login.do?serviceurl=%2Fhome.do'
 
41
defaultShowURL = 'http://show.zoho.com/login.do'
 
42
defaultURL = 'http://www.zoho.com'
38
43
 
39
44
def main(argv):
40
45
        ''' Main entry point '''
41
46
        # make sure we have the required command line arguments
42
47
        try:
43
 
                opts, args = getopt.getopt(argv, "hf:t:u:",
 
48
                opts, args = getopt.getopt(argv, "hf::t:u:",
44
49
                                                ["help",
45
50
                                                 "filename=",
46
51
                                                 "type=",
47
52
                                                 "url="])
48
 
        except getopt.GetoptError:
49
 
                usage()              
50
 
 
 
53
 
 
54
        except getopt.GetoptError:
 
55
                usage()
 
56
 
 
57
        # arguments present and correct
51
58
        filename = ''
52
59
        docType  = ''
53
60
        online   = ''
69
76
                sys.exit()
70
77
 
71
78
        # wanting to display a local document
72
 
        if filename and docType:
73
 
                # first figure out what format this document is in
 
79
        if docType:
 
80
                # first figure out what type of document and give a default
 
81
                # file extension
74
82
                if docType == 'doc':
75
83
                        offlineURL = docURL
 
84
                        extension = "odt"
76
85
                elif docType == 'sheet':
77
86
                        offlineURL = sheetURL
 
87
                        extension = "ods"
78
88
                elif docType == 'show':
79
89
                        offlineURL = showURL
 
90
                        extension = "odp"
80
91
                else:
81
92
                        usage()
82
93
 
83
 
                # ensure that the passed in filename is actually a file
 
94
                # ensure that the passed in filename is actually a file, allow
 
95
                # an empty filename
84
96
                if not os.path.isfile(filename):
85
 
                        unsupported(filename)
 
97
                        if filename != "":
 
98
                                unsupported(filename)
 
99
                        # passed in no filename but a type, launch Zoho with
 
100
                        # an empty document of that type
 
101
                        else:
 
102
                                filename = "/usr/share/webservice-office-zoho/empty-zoho-document." + extension
 
103
                                try:
 
104
                                        f = open(filename)
 
105
                                except IOError:
 
106
                                        print "Could not open file: " + filename
 
107
                                        sys.exit()
86
108
 
87
109
                # ensure that the filename and extension is more than 4 characters
 
110
                # if not use the default from above
88
111
                if len(filename) >= 4:
89
112
                        # find out the documents type
90
113
                        if filename[-4] == '.':
91
114
                                extension = filename[-3:].upper()
92
115
                        else:
93
116
                                extension = filename[-4:].upper()
94
 
                else:
95
 
                        unsupported(filename)
 
117
 
96
118
        else:
97
119
                usage()
98
120
 
110
132
                        [("content", (curlObject.FORM_FILE, filename)),
111
133
                         ("filename", filename), 
112
134
                         ("id", '99'),
113
 
                         ("format", extension),
114
 
                         ("saveurl", 'http://localhost/')])
 
135
                         ("format", extension)])
115
136
 
116
137
        # handle the call differently depending on what service we are using.
117
138
        if docType == 'doc':
122
143
        curlObject.close()
123
144
 
124
145
        # display the document in a browser
 
146
        finalURL = ''
125
147
        if docType == 'doc':
126
148
                x = response.contents.split('\'')
127
149
                for i in x:
135
157
 
136
158
        if finalURL:
137
159
                webbrowser.open(finalURL)
 
160
        else:
 
161
                print "Document failed to be displayed using Zoho web services"
138
162
 
139
163
class requestCallback:
140
164
        ''' A class to hold call back information from the online web service '''