Skip to content

Commit

Permalink
Merge pull request #288 from oliverkurth/topic/okurth/json-output
Browse files Browse the repository at this point in the history
Add json output
  • Loading branch information
oliverkurth authored May 6, 2022
2 parents 0bf7031 + e43a1ae commit 40851e7
Show file tree
Hide file tree
Showing 27 changed files with 1,557 additions and 246 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-tdnf-rpms.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: tdnf CI
name: tdnf RPMs

on: [pull_request, push, workflow_dispatch]

Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION "${CMAKE_IN
set(LIB_TDNF "tdnf")
set(LIB_TDNF_SOLV "tdnfsolv")
set(LIB_TDNF_COMMON "common")
set(LIB_TDNF_JSONDUMP "jsondump")
set(LIB_TDNF_CLI tdnfcli)

add_subdirectory("${PROJECT_SOURCE_DIR}/common")
add_subdirectory("${PROJECT_SOURCE_DIR}/client")
add_subdirectory("${PROJECT_SOURCE_DIR}/jsondump")
add_subdirectory("${PROJECT_SOURCE_DIR}/plugins")
add_subdirectory("${PROJECT_SOURCE_DIR}/python")
add_subdirectory("${PROJECT_SOURCE_DIR}/etc")
Expand Down
4 changes: 1 addition & 3 deletions ci/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ rm -rf build
mkdir -p build
cd build || exit 1

cmake .. && make -j32 && make python -j32

make check -j32
cmake .. && make -j32 && make python -j32 && make check -j32

if ! flake8 ../pytests ; then
echo "flake8 tests failed"
Expand Down
3 changes: 2 additions & 1 deletion client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2021 VMware, Inc. All Rights Reserved.
# Copyright (C) 2020-2022 VMware, Inc. All Rights Reserved.
#
# Licensed under the GNU General Public License v2 (the "License");
# you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -46,6 +46,7 @@ add_library(${LIB_TDNF} SHARED

target_link_libraries(${LIB_TDNF}
${LIB_TDNF_COMMON}
${LIB_TDNF_JSONDUMP}
${LIB_TDNF_SOLV}
${RPM_LIBRARIES}
${LibSolv_LIBRARIES}
Expand Down
1 change: 1 addition & 0 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ TDNFOpenHandle(
IsTdnfAlreadyRunning();

GlobalSetQuiet(pArgs->nQuiet);
GlobalSetJson(pArgs->nJsonOutput);

dwError = TDNFAllocateMemory(1, sizeof(TDNF), (void**)&pTdnf);
BAIL_ON_TDNF_ERROR(dwError);
Expand Down
1 change: 1 addition & 0 deletions client/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ TDNFCloneCmdArgs(
pCmdArgs->nDisableExcludes = pCmdArgsIn->nDisableExcludes;
pCmdArgs->nDownloadOnly = pCmdArgsIn->nDownloadOnly;
pCmdArgs->nNoAutoRemove = pCmdArgsIn->nNoAutoRemove;
pCmdArgs->nJsonOutput = pCmdArgsIn->nJsonOutput;

dwError = TDNFAllocateString(
pCmdArgsIn->pszInstallRoot,
Expand Down
15 changes: 14 additions & 1 deletion common/log.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 VMware, Inc. All Rights Reserved.
* Copyright (C) 2019-2022 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand All @@ -9,6 +9,7 @@
#include "includes.h"

static bool isQuiet = false;
static bool isJson = false;

void GlobalSetQuiet(int32_t val)
{
Expand All @@ -18,6 +19,14 @@ void GlobalSetQuiet(int32_t val)
}
}

void GlobalSetJson(int32_t val)
{
if (val > 0)
{
isJson = true;
}
}

void log_console(int32_t loglevel, const char *format, ...)
{
va_list args;
Expand All @@ -34,6 +43,10 @@ void log_console(int32_t loglevel, const char *format, ...)
{
case LOG_INFO:
case LOG_CRIT:
if (isJson)
{
goto end;
}
if (loglevel == LOG_INFO && isQuiet)
{
goto end;
Expand Down
5 changes: 5 additions & 0 deletions common/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ GlobalSetQuiet(
int32_t val
);

void
GlobalSetJson(
int32_t val
);

void
log_console(
int32_t loglevel,
Expand Down
38 changes: 34 additions & 4 deletions include/tdnf-common-defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,36 @@
} \
} while(0)

#define BAIL_ON_TDNF_SYSTEM_ERROR_UNCOND(dwError) \
do { \
dwError = ERROR_TDNF_SYSTEM_BASE + dwError; \
goto error; \
#define BAIL_ON_TDNF_SYSTEM_ERROR_UNCOND(dwError) \
do { \
dwError = ERROR_TDNF_SYSTEM_BASE + dwError; \
goto error; \
} while(0)

#define CHECK_JD_RC(rc) \
{ \
if ((rc) != 0) { \
dwError = ERROR_TDNF_JSONDUMP; \
BAIL_ON_CLI_ERROR(dwError); \
} \
}

#define CHECK_JD_NULL(jd) \
{ \
if ((jd) == NULL) { \
dwError = ERROR_TDNF_JSONDUMP; \
BAIL_ON_CLI_ERROR(dwError); \
} \
}

#define JD_SAFE_DESTROY(jd) \
{ \
if (jd) { \
jd_destroy(jd); \
jd = NULL; \
} \
}

#define TDNF_SAFE_FREE_MEMORY(pMemory) \
do { \
if (pMemory) { \
Expand Down Expand Up @@ -66,6 +90,12 @@
#define pr_err(fmt, ...) \
log_console(LOG_ERR, fmt, ##__VA_ARGS__)

#define pr_json(str) \
fputs(str, stdout)

#define pr_jsonf(fmt, ...) \
fprintf(stdout, fmt, ##__VA_ARGS__)

/*
* If something needs to be printed (a prompt for example)
* irrespective of 'quiet' option
Expand Down
10 changes: 8 additions & 2 deletions include/tdnfcli.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2021 VMware, Inc. All Rights Reserved.
* Copyright (C) 2017-2022 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -105,7 +105,8 @@ TDNFCliParsePackageArgs(

uint32_t
TDNFCliPrintError(
uint32_t dwErrorCode
uint32_t dwErrorCode,
int doJson
);

uint32_t
Expand Down Expand Up @@ -285,6 +286,11 @@ PrintSolvedInfo(
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
);

uint32_t
PrintSolvedInfoJson(
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
);

uint32_t
PrintNotAvailable(
char** ppszPkgsNotAvailable
Expand Down
2 changes: 2 additions & 0 deletions include/tdnferror.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ extern "C" {
#define ERROR_TDNF_ACCESS_DENIED (ERROR_TDNF_SYSTEM_BASE + EACCES)
#define ERROR_TDNF_ALREADY_EXISTS (ERROR_TDNF_SYSTEM_BASE + EEXIST)

#define ERROR_TDNF_JSONDUMP 1700

#define ERROR_TDNF_PLUGIN_BASE 2000

#define ERROR_TDNF_BASEURL_DOES_NOT_EXISTS 2500
Expand Down
1 change: 1 addition & 0 deletions include/tdnftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ typedef struct _TDNF_CMD_ARGS
int nDisableExcludes; //disable excludes from tdnf.conf
int nDownloadOnly; //download packages only, no install
int nNoAutoRemove; //overide clean_requirements_on_remove config option
int nJsonOutput; //output in json format
char* pszDownloadDir; //directory for download, if nDownloadOnly is set
char* pszInstallRoot; //set install root
char* pszConfFile; //set conf file location
Expand Down
21 changes: 21 additions & 0 deletions jsondump/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (C) 2020-2022 VMware, Inc. All Rights Reserved.
#
# Licensed under the GNU General Public License v2 (the "License");
# you may not use this file except in compliance with the License. The terms
# of the License are located in the COPYING file of this distribution.
#

set(TDNF_JSON_BIN jsondumptest)

add_executable(${TDNF_JSON_BIN}
test.c
)

add_library(${LIB_TDNF_JSONDUMP}
jsondump.c
)

target_link_libraries(${TDNF_JSON_BIN}
${LIB_TDNF_JSONDUMP}
)
Loading

0 comments on commit 40851e7

Please sign in to comment.