Example #1
0
PyObject *
py_checksum_name_str(PyObject *self, PyObject *args)
{
    int type;

    CR_UNUSED(self);

    if (!PyArg_ParseTuple(args, "i:py_checksum_name_Str", &type))
        return NULL;

    return PyStringOrNone_FromString(cr_checksum_name_str(type));
}
Example #2
0
PyObject *
py_checksum_type(PyObject *self, PyObject *args)
{
    char *type;

    CR_UNUSED(self);

    if (!PyArg_ParseTuple(args, "s:py_checksum_type", &type))
        return NULL;

    return PyLong_FromLong((long) cr_checksum_type(type));
}
Example #3
0
void CRThreadExecutor::stop() {
    {
        CRGuard guard(_monitor);
        CR_UNUSED(guard);
        _stopped = true;
        while (_queue.length() > 0) {
            CRRunnable * p = _queue.popFront();
            delete p;
        }
        _monitor->notify();
    }
    _thread->join();
}
static int
newpkgcb_interrupt(cr_Package **pkg,
                   const char *pkgId,
                   const char *name,
                   const char *arch,
                   void *cbdata,
                   GError **err)
{
    CR_UNUSED(pkgId);
    CR_UNUSED(name);
    CR_UNUSED(arch);
    CR_UNUSED(cbdata);

    g_assert(pkg != NULL);
    g_assert(*pkg == NULL);
    g_assert(pkgId != NULL);
    g_assert(!err || *err == NULL);

    if (cbdata) *((int *)cbdata) += 1;

    return CR_CB_RET_ERR;
}
static int
newpkgcb_skip_fake_bash(cr_Package **pkg,
                        const char *pkgId,
                        const char *name,
                        const char *arch,
                        void *cbdata,
                        GError **err)
{
    CR_UNUSED(pkgId);
    CR_UNUSED(arch);
    CR_UNUSED(cbdata);

    g_assert(pkg != NULL);
    g_assert(*pkg == NULL);
    g_assert(pkgId != NULL);
    g_assert(!err || *err == NULL);

    if (!g_strcmp0(name, "fake_bash"))
        return CRE_OK;

    *pkg = cr_package_new();
    return CR_CB_RET_OK;
}
Example #6
0
int CRFileHist::findEntry( const lString16 & fname, const lString16 & fpath, lvsize_t sz )
{
    CR_UNUSED(fpath);
    for ( int i=0; i<_records.length(); i++ ) {
        CRFileHistRecord * rec = _records[i];
        if ( rec->getFileName().compare(fname) )
            continue;
        if ( rec->getFileSize()!=sz ) {
            CRLog::warn("CRFileHist::findEntry() Filename matched %s but sizes are different %d!=%d", LCSTR(fname), sz, rec->getFileSize() );
            continue;
        }
        return i;
    }
    return -1;
}
Example #7
0
static PyObject *
close_db(_SqliteObject *self, void *nothing)
{
    GError *err = NULL;

    CR_UNUSED(nothing);

    if (self->db) {
        cr_db_close(self->db, &err);
        self->db = NULL;
        if (err) {
            nice_exception(&err, NULL);
            return NULL;
        }
    }

    Py_RETURN_NONE;
}
Example #8
0
 /// called on text
 virtual void OnText( const lChar16 * text, int len, lUInt32 flags )
 {
     CR_UNUSED(flags);
     lString16 txt( text, len );
     switch (state) {
     case in_start_point:
         _curr_bookmark->setStartPos( txt );
         break;
     case in_end_point:
         _curr_bookmark->setEndPos( txt );
         break;
     case in_header_txt:
         _curr_bookmark->setTitleText( txt );
         break;
     case in_selection_txt:
         _curr_bookmark->setPosText( txt );
         break;
     case in_comment_txt:
         _curr_bookmark->setCommentText( txt );
         break;
     case in_author:
         _curr_file->setAuthor( txt );
         break;
     case in_title:
         _curr_file->setTitle( txt );
         break;
     case in_series:
         _curr_file->setSeries( txt );
         break;
     case in_filename:
         _curr_file->setFileName( txt );
         break;
     case in_filepath:
         _curr_file->setFilePath( txt );
         break;
     case in_filesize:
         _curr_file->setFileSize( txt.atoi() );
         break;
     default:
         break;
     }
 }
Example #9
0
PyObject *
py_xml_from_rpm(PyObject *self, PyObject *args)
{
    CR_UNUSED(self);

    PyObject *tuple;
    int checksum_type, changelog_limit;
    char *filename, *location_href, *location_base;
    struct cr_XmlStruct xml_res;
    GError *tmp_err = NULL;

    if (!PyArg_ParseTuple(args, "sizzi:py_xml_from_rpm",
                                         &filename,
                                         &checksum_type,
                                         &location_href,
                                         &location_base,
                                         &changelog_limit)) {
        return NULL;
    }

    xml_res = cr_xml_from_rpm(filename, checksum_type, location_href,
                              location_base, changelog_limit, NULL, &tmp_err);
    if (tmp_err) {
        nice_exception(&tmp_err, "Cannot load %s: ", filename);
        return NULL;
    }

    if ((tuple = PyTuple_New(3)) == NULL)
        goto py_xml_from_rpm_end; // Free xml_res and return NULL

    PyTuple_SetItem(tuple, 0, PyStringOrNone_FromString(xml_res.primary));
    PyTuple_SetItem(tuple, 1, PyStringOrNone_FromString(xml_res.filelists));
    PyTuple_SetItem(tuple, 2, PyStringOrNone_FromString(xml_res.other));

py_xml_from_rpm_end:
    free(xml_res.primary);
    free(xml_res.filelists);
    free(xml_res.other);

    return tuple;
}
Example #10
0
 /// called on opening tag
 virtual ldomNode * OnTagOpen( const lChar16 * nsname, const lChar16 * tagname)
 {
     CR_UNUSED(nsname);
     if ( lStr_cmp(tagname, "FictionBookMarks")==0 && state==in_xml ) {
         state = in_fbm;
     } else if ( lStr_cmp(tagname, "file")==0 && state==in_fbm ) {
         state = in_file;
         _curr_file = new CRFileHistRecord();
     } else if ( lStr_cmp(tagname, "file-info")==0 && state==in_file ) {
         state = in_file_info;
     } else if ( lStr_cmp(tagname, "bookmark-list")==0 && state==in_file ) {
         state = in_bm_list;
     } else if ( lStr_cmp(tagname, "doc-title")==0 && state==in_file_info ) {
         state = in_title;
     } else if ( lStr_cmp(tagname, "doc-author")==0 && state==in_file_info ) {
         state = in_author;
     } else if ( lStr_cmp(tagname, "doc-series")==0 && state==in_file_info ) {
         state = in_series;
     } else if ( lStr_cmp(tagname, "doc-filename")==0 && state==in_file_info ) {
         state = in_filename;
     } else if ( lStr_cmp(tagname, "doc-filepath")==0 && state==in_file_info ) {
         state = in_filepath;
     } else if ( lStr_cmp(tagname, "doc-filesize")==0 && state==in_file_info ) {
         state = in_filesize;
     } else if ( lStr_cmp(tagname, "bookmark")==0 && state==in_bm_list ) {
         state = in_bm;
         _curr_bookmark = new CRBookmark();
     } else if ( lStr_cmp(tagname, "start-point")==0 && state==in_bm ) {
         state = in_start_point;
     } else if ( lStr_cmp(tagname, "end-point")==0 && state==in_bm ) {
         state = in_end_point;
     } else if ( lStr_cmp(tagname, "header-text")==0 && state==in_bm ) {
         state = in_header_txt;
     } else if ( lStr_cmp(tagname, "selection-text")==0 && state==in_bm ) {
         state = in_selection_txt;
     } else if ( lStr_cmp(tagname, "comment-text")==0 && state==in_bm ) {
         state = in_comment_txt;
     }
     return NULL;
 }
Example #11
0
void CRThreadExecutor::run() {
    CRLog::trace("Starting thread executor");
    for (;;) {
        if (_stopped)
            break;
        CRRunnable * task = NULL;
        {
            CRGuard guard(_monitor);
            CR_UNUSED(guard);
            if (_queue.length() == 0)
                _monitor->wait();
            if (_stopped)
                break;
            task = _queue.popFront();
        }
        // process next event
        if (task) {
            task->run();
            delete task;
        }
    }
    CRLog::trace("Exiting thread executor");
}
Example #12
0
 /// called on element attribute
 virtual void OnAttribute( const lChar16 * nsname, const lChar16 * attrname, const lChar16 * attrvalue )
 {
     CR_UNUSED(nsname);
     if ( lStr_cmp(attrname, "type")==0 && state==in_bm ) {
         static const char * tnames[] = {"lastpos", "position", "comment", "correction"};
         for ( int i=0; i<4; i++) {
             if ( lStr_cmp(attrvalue, tnames[i])==0 ) {
                 _curr_bookmark->setType( (bmk_type)i );
                 return;
             }
         }
     } else if ( lStr_cmp(attrname, "shortcut")==0 && state==in_bm ) {
         int n = lString16( attrvalue ).atoi();
         _curr_bookmark->setShortcut( n );
     } else if ( lStr_cmp(attrname, "percent")==0 && state==in_bm ) {
         int n1=0, n2=0;
         int i=0;
         for ( ; attrvalue[i]>='0' && attrvalue[i]<='9'; i++)
             n1 = n1*10 + (attrvalue[i]-'0');
         if ( attrvalue[i]=='.' ) {
             i++;
             if (attrvalue[i]>='0' && attrvalue[i]<='9')
                 n2 = (attrvalue[i++]-'0')*10;
             if (attrvalue[i]>='0' && attrvalue[i]<='9')
                 n2 = (attrvalue[i++]-'0');
         }
         _curr_bookmark->setPercent( n1*100 + n2 );
     } else if ( lStr_cmp(attrname, "timestamp")==0 && state==in_bm ) {
         time_t n1=0;
         int i=0;
         for ( ; attrvalue[i]>='0' && attrvalue[i]<='9'; i++)
             n1 = n1*10 + (attrvalue[i]-'0');
         _curr_bookmark->setTimestamp( n1 );
     } else if (lStr_cmp(attrname, "page")==0 && state==in_bm) {
         _curr_bookmark->setBookmarkPage(lString16( attrvalue ).atoi());
     }
 }
Example #13
0
static int
metadatalocation_init(_MetadataLocationObject *self, PyObject *args, PyObject *kwds)
{
    CR_UNUSED(kwds);
    char *repopath;
    int ignore_db;
    GError *tmp_err = NULL;

    if (!PyArg_ParseTuple(args, "si|:metadatalocation_init", &repopath, &ignore_db))
        return -1;

    /* Free all previous resources when reinitialization */
    if (self->ml) {
        cr_metadatalocation_free(self->ml);
    }

    /* Init */
    self->ml = cr_locate_metadata(repopath, ignore_db, &tmp_err);
    if (tmp_err) {
        nice_exception(&tmp_err, NULL);
        return -1;
    }
    return 0;
}
Example #14
0
static int
sqlite_init(_SqliteObject *self, PyObject *args, PyObject *kwds)
{
    char *path;
    int db_type;
    GError *err = NULL;
    PyObject *ret;

    CR_UNUSED(kwds);

    if (!PyArg_ParseTuple(args, "si|:sqlite_init", &path, &db_type))
        return -1;

    /* Check arguments */
    if (db_type < CR_DB_PRIMARY || db_type >= CR_DB_SENTINEL) {
        PyErr_SetString(PyExc_ValueError, "Unknown db type");
        return -1;
    }

    /* Free all previous resources when reinitialization */
    ret = close_db(self, NULL);
    Py_XDECREF(ret);
    if (ret == NULL) {
        // Error encountered!
        return -1;
    }

    /* Init */
    self->db = cr_db_open(path, db_type, &err);
    if (err) {
        nice_exception(&err, NULL);
        return -1;
    }

    return 0;
}
Example #15
0
static void
fixtures_setup(TestFixtures *fixtures, gconstpointer test_data)
{
    CR_UNUSED(test_data);
    gchar *template = g_strdup(TMPDIR_TEMPLATE);
Example #16
0
static PyObject *
metadatalocation_repr(_MetadataLocationObject *self)
{
    CR_UNUSED(self);
    return PyString_FromFormat("<createrepo_c.MetadataLocation object>");
}
Example #17
0
/// moves selection, returns true if selection is moved, and it's necessary to ensure positionToShow is visible on screen
bool ldomTextSelectionTool::doCommand( int cmd, int param, ldomXPointer &positionToShow )
{
    CR_UNUSED(param);
    int count = 1;
    if ( cmd>1 && cmd<20 )
        count = cmd;
    switch (cmd) {
    case CMD_SEL_MIDDLE_WORD:           // select middle word for initial interval
        return selectMiddleInterval( WORD, positionToShow );
    case CMD_SEL_MIDDLE_SENTENCE:       // select middle sentence for initial interval
        return selectMiddleInterval( SENTENCE, positionToShow );
    case CMD_SEL_MIDDLE_PARA:            // select middle paragraph for initial interval
        return selectMiddleInterval( PARA, positionToShow );
    case CMD_SEL_MIDDLE_INTERVAL:        // select middle interval (word/sentence/paragraph depending on current setting) for initial interval
        return selectMiddleInterval( _currInterval, positionToShow );
    case CMD_SEL_CUR_MODE_TOGGLE:        // toggle current mode: start/end/both
        _currOrigin = (origin_t)(((int)_currOrigin+1)%3);
        return false;
    case CMD_SEL_CUR_MODE_START:         // set current mode to start
        _currOrigin = START;
        return false;
    case CMD_SEL_CUR_MODE_END:           // set current mode to end
        _currOrigin = END;
        return false;
    case CMD_SEL_CUR_MODE_ALL:           // set current mode to start+end
        _currOrigin = ALL;
        return false;
    case CMD_SEL_CUR_INTERVAL_TOGGLE:    // toggle current interval: paragraph/sentence/word
        _currInterval = (interval_t)(((int)_currInterval+1)%3);
        return false;
    case CMD_SEL_CUR_INTERVAL_WORD:      // set current interval to word
        _currInterval = WORD;
        return false;
    case CMD_SEL_CUR_INTERVAL_SENTENCE:  // set current interval to sentence
        _currInterval = SENTENCE;
        return false;
    case CMD_SEL_CUR_INTERVAL_PARA:      // set current interval to paragraph
        _currInterval = PARA;
        return false;
    case CMD_SEL_START_FWD_BY_WORD:      // move selection start - forward by word
        return moveBy( WORD, FORWARD, START, count, positionToShow );
    case CMD_SEL_START_FWD_BY_SENTENCE:  // move selection start - forward by sentence
        return moveBy( SENTENCE, FORWARD, START, count, positionToShow );
    case CMD_SEL_START_FWD_BY_PARA:      // move selection start - forward by paragraph
        return moveBy( PARA, FORWARD, START, count, positionToShow );
    case CMD_SEL_START_FWD_BY_INTERVAL:  // move selection start - forward by current interval (word/sentence/para)
        return moveBy( _currInterval, FORWARD, START, count, positionToShow );
    case CMD_SEL_START_BACK_BY_WORD:     // move selection start - back by word
        return moveBy( WORD, BACK, START, count, positionToShow );
    case CMD_SEL_START_BACK_BY_SENTENCE: // move selection start - back by sentence
        return moveBy( WORD, BACK, START, count, positionToShow );
    case CMD_SEL_START_BACK_BY_PARA:     // move selection start - back by paragraph
        return moveBy( WORD, BACK, START, count, positionToShow );
    case CMD_SEL_START_BACK_BY_INTERVAL: // move selection start - back by interval (word/sentence/para)
        return moveBy( _currInterval, BACK, START, count, positionToShow );
    case CMD_SEL_END_FWD_BY_WORD:        // move selection end - forward by word
        return moveBy( WORD, FORWARD, END, count, positionToShow );
    case CMD_SEL_END_FWD_BY_SENTENCE:    // move selection end - forward by sentence
        return moveBy( SENTENCE, FORWARD, END, count, positionToShow );
    case CMD_SEL_END_FWD_BY_PARA:        // move selection end - forward by paragraph
        return moveBy( PARA, FORWARD, END, count, positionToShow );
    case CMD_SEL_END_FWD_BY_INTERVAL:    // move selection end - forward by interval (word/sentence/para)
        return moveBy( _currInterval, FORWARD, END, count, positionToShow );
    case CMD_SEL_END_BACK_BY_WORD:       // move selection end - back by word
        return moveBy( WORD, BACK, END, count, positionToShow );
    case CMD_SEL_END_BACK_BY_SENTENCE:   // move selection end - back by sentence
        return moveBy( SENTENCE, BACK, END, count, positionToShow );
    case CMD_SEL_END_BACK_BY_PARA:       // move selection end - back by paragraph
        return moveBy( PARA, BACK, END, count, positionToShow );
    case CMD_SEL_END_BACK_BY_INTERVAL:   // move selection end - back by interval (word/sentence/para)
        return moveBy( _currInterval, BACK, END, count, positionToShow );
    case CMD_SEL_ALL_FWD_BY_WORD:        // move selection start+end - forward by word
        return moveBy( WORD, FORWARD, ALL, count, positionToShow );
    case CMD_SEL_ALL_FWD_BY_SENTENCE:    // move selection start+end - forward by sentence
        return moveBy( SENTENCE, FORWARD, ALL, count, positionToShow );
    case CMD_SEL_ALL_FWD_BY_PARA:        // move selection start+end - forward by paragraph
        return moveBy( PARA, FORWARD, ALL, count, positionToShow );
    case CMD_SEL_ALL_FWD_BY_INTERVAL:    // move selection start+end - forward by interval (word/sentence/para)
        return moveBy( _currInterval, FORWARD, ALL, count, positionToShow );
    case CMD_SEL_ALL_BACK_BY_WORD:       // move selection start+end - back by word
        return moveBy( WORD, BACK, ALL, count, positionToShow );
    case CMD_SEL_ALL_BACK_BY_SENTENCE:   // move selection start+end - back by sentence
        return moveBy( SENTENCE, BACK, ALL, count, positionToShow );
    case CMD_SEL_ALL_BACK_BY_PARA:       // move selection start+end - back by paragraph
        return moveBy( PARA, BACK, ALL, count, positionToShow );
    case CMD_SEL_ALL_BACK_BY_INTERVAL:   // move selection start+end - back by interval (word/sentence/para)
        return moveBy( _currInterval, BACK, ALL, count, positionToShow );
    case CMD_SEL_CUR_FWD_BY_WORD:        // move selection depending on current mode (start/end/both) - forward by word
        return moveBy( WORD, FORWARD, _currOrigin, count, positionToShow );
    case CMD_SEL_CUR_FWD_BY_SENTENCE:    // move selection depending on current mode (start/end/both) - forward by sentence
        return moveBy( SENTENCE, FORWARD, _currOrigin, count, positionToShow );
    case CMD_SEL_CUR_FWD_BY_PARA:        // move selection depending on current mode (start/end/both) - forward by paragraph
        return moveBy( PARA, FORWARD, _currOrigin, count, positionToShow );
    case CMD_SEL_CUR_FWD_BY_INTERVAL:    // move selection depending on current mode (start/end/both) - forward by interval (word/sentence/para)
        return moveBy( _currInterval, FORWARD, _currOrigin, count, positionToShow );
    case CMD_SEL_CUR_BACK_BY_WORD:       // move selection depending on current mode (start/end/both) - back by word
        return moveBy( WORD, BACK, _currOrigin, count, positionToShow );
    case CMD_SEL_CUR_BACK_BY_SENTENCE:   // move selection depending on current mode (start/end/both) - back by sentence
        return moveBy( SENTENCE, BACK, _currOrigin, count, positionToShow );
    case CMD_SEL_CUR_BACK_BY_PARA:       // move selection depending on current mode (start/end/both) - back by paragraph
        return moveBy( PARA, BACK, _currOrigin, count, positionToShow );
    case CMD_SEL_CUR_BACK_BY_INTERVAL:   // move selection depending on current mode (start/end/both) - back by interval (word/sentence/para)
        return moveBy( _currInterval, BACK, _currOrigin, count, positionToShow );
    }
    return false;
}