Пример #1
0
Файл: ls.py Проект: qmutz/osh
 def setup(self):
     args = self.args()
     depth0 = args.flag('-0')
     depth1 = args.flag('-1')
     recursive = args.flag('-r')
     count = 0
     if depth0:
         count += 1
         self._lister = _Lister0(self)
     if depth1:
         count += 1
         self._lister = _Lister1(self)
     if recursive:
         count += 1
         self._lister = _ListerRecursive(self)
     if count == 0:
         self._lister = _Lister1(self)
     elif count > 1:
         self.usage()
     self._list_file = args.flag('-f')
     self._list_dir = args.flag('-d')
     self._list_link = args.flag('-s')
     if not (self._list_file or self._list_dir or self._list_link):
         self._list_file = True
         self._list_dir = True
         self._list_link = True
     self._patterns = args.remaining()
     if len(self._patterns) == 0:
         self._patterns = ['.']
Пример #2
0
Файл: imp.py Проект: qmutz/osh
 def setup(self):
     args = self.args()
     for module_name in args.remaining():
         exec('import %s' % module_name)
         dot = module_name.find('.')
         if dot < 0:
             top_module_name = module_name
         else:
             top_module_name = module_name[:dot]
         osh.core.add_to_namespace(top_module_name, locals()[top_module_name])
Пример #3
0
Файл: red.py Проект: qmutz/osh
    def setup(self):
        args = self.args()
        running = args.flag('-r')
        if running is None:
            running = False
        functions = args.remaining()
        # A "group" position contains a dot, used to indicate grouping.
        # A "data" position does not contain a dot; it contains data that will be aggregated.
        group_positions = []
        data_positions = []
        for p in xrange(len(functions)):
            f = functions[p]
            if f == '.' or f is None:
                group_positions.append(p)
            else:
                data_positions.append(p)
        n_group = len(group_positions)
        n_data = len(data_positions)
        functions = [create_function(functions[p]) for p in data_positions]
        initial_value = (None, ) * n_data
        if n_group == 0:

            def aggregator(*t):
                if t[:n_data] == initial_value:
                    # all None => first item, need to initialize accumulator
                    accumulator = t[-n_data:]
                else:
                    accumulator = tuple([
                        functions[p](t[p], t[n_data + p])
                        for p in xrange(n_data)
                    ])
                return accumulator

            self._aggregate = _NonGroupingAggregate(self, running,
                                                    initial_value, aggregator)
        else:

            def grouper(*t):
                return tuple([t[p] for p in group_positions])

            def aggregator(*t):
                if reduce(lambda r, x: r and x is None, t[:n_data], True):
                    # all None => first item, need to initialize accumulator
                    accumulator = tuple([
                        t[n_data + data_positions[p]] for p in xrange(n_data)
                    ])
                else:
                    accumulator = tuple([
                        functions[p](t[p], t[n_data + data_positions[p]])
                        for p in xrange(n_data)
                    ])
                return accumulator

            self._aggregate = _GroupingAggregate(self, running, grouper,
                                                 initial_value, aggregator)
Пример #4
0
 def setup(self):
     args = self.args()
     running = args.flag('-r')
     if running is None:
         running = False
     functions = args.remaining()
     # A "group" position contains a dot, used to indicate grouping.
     # A "data" position does not contain a dot; it contains data that will be aggregated.
     group_positions = []
     data_positions = []
     for p in xrange(len(functions)):
         f = functions[p]
         if f == '.' or f is None:
             group_positions.append(p)
         else:
             data_positions.append(p)
     n_group = len(group_positions)
     n_data = len(data_positions)
     functions = [create_function(functions[p]) for p in data_positions]
     initial_value = (None,) * n_data
     if n_group == 0:
         def aggregator(*t):
             if t[:n_data] == initial_value:
                 # all None => first item, need to initialize accumulator
                 accumulator = t[-n_data:]
             else:
                 accumulator = tuple([functions[p](t[p], t[n_data + p])
                                      for p in xrange(n_data)])
             return accumulator
         self._aggregate = _NonGroupingAggregate(self,
                                                 running,
                                                 initial_value,
                                                 aggregator)
     else:
         def grouper(*t):
             return tuple([t[p] for p in group_positions])
         def aggregator(*t):
             if reduce(lambda r, x: r and x is None, t[:n_data], True):
                 # all None => first item, need to initialize accumulator
                 accumulator = tuple([t[n_data + data_positions[p]]
                                      for p in xrange(n_data)])
             else:
                 accumulator = tuple([functions[p](t[p], t[n_data + data_positions[p]])
                                      for p in xrange(n_data)])
             return accumulator
         self._aggregate = _GroupingAggregate(self,
                                              running,
                                              grouper,
                                              initial_value,
                                              aggregator)