Пример #1
0
    def saveSelections(self):
        """
        savasfilename can't append to a file - if the file exists an error
        message pops up.
        if output specified, don't ask (put it in window in menubar?)
        """
        filename = asksaveasfilename(title="Save points into a doc file",
                                     initialfile=self.savefilename)
        if len(filename) == 0:
            return

        # construct a dictionary to pass to writedocfile
        headers = ['file_number', 'class']
        F = {}
        key = self.startkey.get()
        try:
            key = int(key)
        except:
            key = 1

        for photo in self.photolist:
            filenumber = Spiderutils.getfilenumber(photo.filename)
            try:
                int(filenumber)
                if hasattr(photo, 'selectvalue'):
                    val = photo.selectvalue
                else:
                    val = '0'
                F[key] = [filenumber, val]
                key = key + 1
            except:
                print "error getting file number from %s" % photo.filename
                continue

        if Spiderutils.writedoc(filename, F, headers=headers, mode='a'):
            showinfo("Data saved to file",
                     "Data written to %s" % os.path.basename(filename))
        else:
            showerror("Error!",
                      "Unable to write to %s" % os.path.basename(filename))
Пример #2
0
    def saveSelections(self):
        """
        Savasfilename can't append to a file - if the file exists an error
        message pops up.
        if output specified, don't ask (put it in window in menubar?)
        """
        filename = asksaveasfilename(title="Save points into a doc file",
                                     initialfile=self.savefilename)
        if len(filename) == 0:
            return

        # Construct a dictionary to pass to writedocfile
        headers = ['file_number', 'class']
        F = {}
        key = self.startkey.get()
        try:
            key = int(key)
        except:
            key = 1

        for photo in self.photolist:
            filenumber = Spiderutils.getfilenumber(photo.filename)
            try:
                int(filenumber)
                if hasattr(photo, 'selectvalue'):
                    val = photo.selectvalue
                else:
                    val = '0'
                F[key] = [filenumber, val]
                key = key + 1
            except:
                print "error getting file number from %s" % photo.filename
                continue

        if Spiderutils.writedoc(filename, F, headers=headers, mode='a'):
            showinfo("Data saved to file", "Data written to %s" % os.path.basename(filename))
        else:
            showerror("Error!", "Unable to write to %s" % os.path.basename(filename))
Пример #3
0
if sys.argv[1:]:
    file = sys.argv[1]
    filename = sys.argv[2]

    F = {}  # initialize dictionary
    key = 0  # initialize key

    if os.path.exists(file):
        input = open(file, 'r')
        L = input.readlines()  # read line-by-line
        input.close()

        # read contents
        for line in L:
            filenum = Spiderutils.getfilenumber(line)
            key += 1
            F[key] = [filenum]
#           print filenum

        headers = ['file_number']
        if Spiderutils.writeSpiderDocFile(filename,
                                          F,
                                          headers=headers,
                                          append=0):
            print 'Wrote', key, 'keys to %s' % os.path.basename(filename)
        else:
            print "Error!", "Unable to write to %s" % os.path.basename(
                filename)
    else:
        print "Error!", "Unable to read %s" % file