~ubuntu-branches/ubuntu/precise/ubuntuone-client/precise

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/fsm/fsm_parser.py

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2011-12-21 15:46:25 UTC
  • mfrom: (1.1.56)
  • Revision ID: package-import@ubuntu.com-20111221154625-ujvunri4frsecj2k
Tags: 2.99.0-0ubuntu1
* New upstream release.
  - Verify timestamp to avoid invalid auth failures (LP: #692597)
  - Files in new UDFs not uploaded due to filtering (LP: #869920)
* debian/patches:
  - Remove upstreamed patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    class ParseError(Exception):
80
80
        """Raised when we cant parse the spreadsheet"""
81
81
 
82
 
 
83
82
    class ODSReader(object):
84
83
        """Reads fsm from spreadsheets"""
85
84
 
96
95
            except NoConnectException:
97
96
                raise Exception(CONNECT_MSG)
98
97
 
99
 
 
100
98
            desktop = context.ServiceManager.createInstanceWithContext(
101
99
                                        "com.sun.star.frame.Desktop", context)
102
100
 
103
101
            cwd = systemPathToFileUrl(os.getcwd())
104
 
            file_url = absolutize( cwd, systemPathToFileUrl(
 
102
            file_url = absolutize(cwd, systemPathToFileUrl(
105
103
                    os.path.join(os.getcwd(), filename)))
106
 
            in_props = PropertyValue( "Hidden" , 0 , True, 0 ),
 
104
            in_props = PropertyValue("Hidden", 0, True, 0),
107
105
            document = desktop.loadComponentFromURL(
108
106
                file_url, "_blank", 0, in_props)
109
107
            self.rules = document.Sheets.getByName(u'rules')
142
140
            rows = [cells]
143
141
 
144
142
            while True:
145
 
                cells = [self.rules.getCellByPosition(i, iter_line).getFormula()
146
 
                                            for i in xrange(line_length)]
 
143
                cells = [
 
144
                    self.rules.getCellByPosition(i, iter_line).getFormula()
 
145
                    for i in xrange(line_length)]
147
146
                if not any(cells):
148
147
                    break
149
148
 
216
215
            try:
217
216
                idx = rows[0].index(name)
218
217
            except ValueError:
219
 
                raise ValueError("Section '%s' not found."%name)
 
218
                raise ValueError("Section '%s' not found." % name)
220
219
            return idx
221
220
 
222
221
        state_idx = get_idx("STATE")
226
225
        action_func_idx = get_idx("ACTION_FUNC")
227
226
        state_out_idx = get_idx("STATE_OUT")
228
227
        row_size = len(rows[0])
 
228
 
229
229
        def get_var_value_from_row_part(row, start, end):
230
230
            'get the values for a row from start-stop columns'
231
231
            vars = {}
233
233
                value = rows[row][i]
234
234
                if not value:
235
235
                    raise ParseError("Cell (%s,%s) needs a value" % (row, i))
236
 
                vars[ rows[2][i] ] = value.strip()
 
236
                vars[rows[2][i]] = value.strip()
237
237
            return vars
238
238
 
239
239
        build_state_from_row = lambda row: get_var_value_from_row_part(
252
252
        names = rows[2][param_idx:action_idx]
253
253
        parameters = dict(zip(names, descs))
254
254
        # generate events
255
 
        events_rowno = [ n for n in range(len(rows))
 
255
        events_rowno = [n for n in range(len(rows))
256
256
                        if rows[n][0] and not rows[n][1]]
257
257
        events = {}
258
258
        for event_rowno in events_rowno:
268
268
                comm = row[comments_idx]
269
269
                afunc = row[action_func_idx]
270
270
                p += 1
271
 
                states.append( dict(STATE=st, STATE_OUT=st_out, PARAMETERS=vars,
 
271
                states.append(dict(STATE=st, STATE_OUT=st_out, PARAMETERS=vars,
272
272
                                ACTION=act, COMMENTS=comm, ACTION_FUNC=afunc))
273
273
            events[event_name] = states
274
274
 
275
275
        # build invalid state list
276
276
        invalid = ods.get_invalid()
277
 
        invalid = [ dict(zip(invalid[0], row)) for row in invalid[1:]]
 
277
        invalid = [dict(zip(invalid[0], row)) for row in invalid[1:]]
278
278
 
279
279
        return dict(events=events, state_vars=state_vars,
280
280
                    parameters=parameters, invalid=invalid)
281
281
 
282
 
 
283
282
    def main():
284
283
        'a simple interface to test the parser'
285
284
        usage = "usage: %prog [options] SPREADSHEET"