Exemple #1
0
def lookup_patch_by_number(patch_list, patch_number):
    """
    Return pair (number, filename) by patch_number.
    If patch not found - return None

    """
    for num, filename in patch_list:
        if (num == patch_number):
            return (num, filename)
        if (atoi(patch_number) == atoi(num)):
            return (num, filename)
Exemple #2
0
    def build_list(self, args, force=False):
        #print 'build list', args, force
        todo_prepare = get_patch_list(_patch_root_dir())
        todo = []
        if len(args):
            for num in args:
                patch_num = atoi(num)
                if not patch_num:
                    print "Warning: %s not is a valid "\
                          "patch number, skipped" % num
                    continue
                patch = lookup_patch_by_number(todo_prepare, patch_num)
                if not patch:
                    print "Warning: %s not found in "\
                          "list of patches, skipped" % num
                    continue

                if not force and is_patchnum_applied(patch[0]):
                    print "Warning: %s patch is allready applied, "\
                          "skipped. (Use -f to force apply)" % num
                    continue

                todo.append(patch)
        else:
            for (num, filename) in todo_prepare:
                #print is_patchnum_applied(num), num
                if force or not is_patchnum_applied(num):
                    todo.append((num, filename))
        return todo
Exemple #3
0
def main():
    start = time()

    GeoCity.objects.all().delete()
    file = codecs.open("/tmp/cities1000.txt", "r", "utf-8")

    for line in file:
        line = line.encode('utf-8')
        items = line.split("\t")

        geo_city = GeoCity(geonameid=atoi(items[0]),
                           name=items[1],
                           asciiname=items[2],
                           alternatenames=items[3],
                           latitude=float(items[4]),
                           longitude=float(items[5]),
                           fclass=items[6],
                           fcode=items[7],
                           country=items[8],
                           cc2=items[9],
                           admin1=items[10],
                           admin2=items[11],
                           admin3=items[12],
                           admin4=items[13],
                           population=atoi(items[14]),
                           elevation=atoi(items[15]),
                           gtopo30=atoi(items[16]),
                           timezone=items[17],
                           moddate=date_or_none(items[18]))
        try:
            geo_city.save()
        except:
            geo_city.alternatenames = ''
            geo_city.save()
        #print geo_city.geonameid, geo_city.name,  geo_city.moddate

    elapsed = time() - start
    print "Elapsed time -->", elapsed
Exemple #4
0
    def _calc(self, page=None):
        if self.request and 'page' in self.request.GET and page is None:
            page = self.request.GET['page']
        self._page = atoi(page,1)

        self.row_per_page = self.row_per_page or settings.PAGINATOR_PER_PAGE

        if type(self._queryset) is ListType:
            self._hits = len(self._queryset)
        else:
            self._hits = int(self._queryset.count())

        self._pages = int(math.ceil(float(self._hits)/float(self.row_per_page)))
        if not self._pages:
            self._pages = 1

        if self._page < 1 or self._page > self._pages:
            raise Http404

        self.segment = 5
Exemple #5
0
    def handle_set_applied(self, *args, **options):
        if not len(args):
            print "Error: specify at least one patch number to be reserved"
            return
        todo_prepare = get_patch_list(_patch_root_dir(), False)
        for num in args:
            patch_num = atoi(num)
            if not patch_num:
                print "Error: %s not is a "\
                      "valid patch number, skipped" % num
                continue

            if is_patchnum_applied(patch_num):
                print "Error: %s already recorded as being applied, skipped." % patch_num
                continue

            self.executor.set_applied_patch(int(patch_num),
                                            dict(todo_prepare)[patch_num])

        print "-> set_applied=%s: Finished." % patch_num
Exemple #6
0
    def handle_reserve(self, *args, **options):
        if not len(args):
            print "Error: specify at least one patch number to be reserved"
            return
        todo_prepare = get_patch_list(_patch_root_dir(), False)
        created = []
        for num in args:
            patch_num = atoi(num)
            if not patch_num:
                print "Warning: %s not is a "\
                      "valid patch number, skipped" % num
                continue

            patch = lookup_patch_by_number(todo_prepare, patch_num)
            if patch:
                print "Warning: %s found in list of patches, skipped." % num
                continue
            newfile = _patch_root_dir() + get_filename_by_number(num)
            open(newfile, "w")
            print "Zero sized patch '%s' has been created." % newfile
        print "\t Done."
def int_field(cell):
    cell = atoi(cell)
    if cell:
        return str(cell)
    else:
        return 'NULL'
Exemple #8
0
 def get_offset(self):
     start = (self.page - 1) * atoi(self.row_per_page)
     end = self.page * atoi(self.row_per_page)
     return (start, end)