Skip to content
22 changes: 2 additions & 20 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ pipeline {
withCredentials([string(credentialsId: params.SONARCLOUD_TOKEN, variable: 'token')]) {
sh(
label: 'Running Sonar Scanner',
script: 'uv run pysonar -t $token -Dsonar.projectVersion=$VERSION -Dsonar.buildString="$BUILD_TAG" -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory -Dsonar.python.coverage.reportPaths=./reports/coverage/coverage-python.xml -Dsonar.cfamily.cobertura.reportPaths=reports/coverage/coverage_cpp.xml ' + (env.CHANGE_ID ? '-Dsonar.pullrequest.key=$CHANGE_ID -Dsonar.pullrequest.base=$CHANGE_TARGET' : '-Dsonar.branch.name=$BRANCH_NAME')
script: 'uv run pysonar -t $token -Dsonar.projectVersion=$VERSION -Dsonar.buildString="$BUILD_TAG" -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.compile-commands=build/build_wrapper_output_directory/compile_commands.json -Dsonar.python.coverage.reportPaths=./reports/coverage/coverage-python.xml -Dsonar.cfamily.cobertura.reportPaths=reports/coverage/coverage_cpp.xml ' + (env.CHANGE_ID ? '-Dsonar.pullrequest.key=$CHANGE_ID -Dsonar.pullrequest.base=$CHANGE_TARGET' : '-Dsonar.branch.name=$BRANCH_NAME')
)
}
}
Expand Down Expand Up @@ -884,25 +884,7 @@ pipeline {
}
post{
cleanup{
cleanWs(
patterns: [
[pattern: '.coverage/', type: 'INCLUDE'],
[pattern: '.eggs/', type: 'INCLUDE'],
[pattern: '.mypy_cache/', type: 'INCLUDE'],
[pattern: '.pytest_cache/', type: 'INCLUDE'],
[pattern: 'dist/', type: 'INCLUDE'],
[pattern: 'build/', type: 'INCLUDE'],
[pattern: '*.dist-info/', type: 'INCLUDE'],
[pattern: 'logs/', type: 'INCLUDE'],
[pattern: 'reports/', type: 'INCLUDE'],
[pattern: 'generatedJUnitFiles/', type: 'INCLUDE'],
[pattern: 'py3exiv2bind/*.so', type: 'INCLUDE'],
[pattern: '**/__pycache__/', type: 'INCLUDE'],
[pattern: 'venv/', type: 'INCLUDE'],
],
notFailBuild: true,
deleteDirs: true
)
sh "git clean -dfx"
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/py3exiv2bind/core/glue/ExifStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include "ExifStrategy.h"
#include "make_dictionary.h"
#include <iostream>
#include <string>
#include <unordered_map>

#include <exiv2/image.hpp>

std::unordered_map<std::string, std::string> ExifStrategy::load(const Exiv2::Image &image){
return make_dictionary(image.exifData());
Expand Down
8 changes: 6 additions & 2 deletions src/py3exiv2bind/core/glue/IPTC_Strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

#include "IPTC_Strategy.h"
#include "make_dictionary.h"
#include <exiv2/error.hpp>
#include <iostream>

#include <exiv2/image.hpp>

#include <string>
#include <unordered_map>


std::unordered_map<std::string, std::string> IPTC_Strategy::load(const Exiv2::Image &image){
return make_dictionary(image.iptcData());
Expand Down
32 changes: 22 additions & 10 deletions src/py3exiv2bind/core/glue/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@
//

#include "Image.h"

#include "MetadataProcessor.h"
#include "glue.h"
#include "MetadataStrategies.h"
#include "glue_execeptions.h"
#include <cassert>

#include <exiv2/error.hpp>
#include <exiv2/image.hpp>
#include <exiv2/types.hpp>

#include <cassert>
#include <iostream>
#include <list>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <unordered_map>

std::ostringstream warning_log;
std::ostringstream error_log;
namespace {
std::ostringstream warning_log;
std::ostringstream error_log;
} // namespace

Image::Image(const std::string &filename) : filename(filename) {
warning_log.clear();
Expand All @@ -22,17 +33,18 @@ Image::Image(const std::string &filename) : filename(filename) {
error_log.str("");
try {
Exiv2::LogMsg::setHandler([](int level, const char *msg) {
switch((Exiv2::LogMsg::Level)level){
switch(static_cast<Exiv2::LogMsg::Level>(level)){

case Exiv2::LogMsg::debug:break;
case Exiv2::LogMsg::info:break;
case Exiv2::LogMsg::debug:
case Exiv2::LogMsg::info:
case Exiv2::LogMsg::mute:
break;
case Exiv2::LogMsg::warn:
warning_log << msg;
break;
case Exiv2::LogMsg::error:
error_log << msg;
break;
case Exiv2::LogMsg::mute:break;
default: break;
}
});
Expand All @@ -43,8 +55,8 @@ Image::Image(const std::string &filename) : filename(filename) {
std::cerr << e.what() << std::endl;
throw std::runtime_error(e.what());
}
std::string warning_msg = warning_log.str();
std::string error_msg = error_log.str();
const std::string warning_msg = warning_log.str();
const std::string error_msg = error_log.str();

if(!warning_msg.empty()){
warning_logs.push_back(warning_msg);
Expand Down
9 changes: 8 additions & 1 deletion src/py3exiv2bind/core/glue/MetadataProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
// Created by hborcher on 10/11/2017.
//

#include "MetadataProcessor.h"
#include "ExifStrategy.h"
#include "IPTC_Strategy.h"
#include "MetadataProcessor.h"
#include "MetadataStrategies.h"
#include "XmpStrategy.h"

#include <exiv2/image.hpp>

#include <memory>
#include <string>
#include <unordered_map>

const std::unordered_map<std::string, std::string> &MetadataProcessor::getMetadata() const {
return metadata;
}
Expand Down
7 changes: 4 additions & 3 deletions src/py3exiv2bind/core/glue/MetadataProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#define PYEXIV2BIND_METADATA_PROCESSOR_H


#include <string>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>

#include "AbsMetadataStrategy.h"
#include "MetadataStrategies.h"

Expand All @@ -19,7 +20,7 @@ struct MetadataProcessor {
public:
void build(const Exiv2::Image &image);
const std::unordered_map<std::string, std::string> &getMetadata() const;
void set_output_format(MetadataStrategies);
void set_output_format(MetadataStrategies metadata_type);
};


Expand Down
7 changes: 6 additions & 1 deletion src/py3exiv2bind/core/glue/XmpStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

#include "XmpStrategy.h"
#include "make_dictionary.h"
#include <iostream>

#include <exiv2/image.hpp>

#include <string>
#include <unordered_map>

std::unordered_map<std::string, std::string> XmpStrategy::load(const Exiv2::Image &image){
return make_dictionary(image.xmpData());
}
19 changes: 14 additions & 5 deletions src/py3exiv2bind/core/glue/glue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@
// Created by hborcher on 10/4/2017.
//
#include "glue.h"
#include <exiv2/exiv2.hpp>


#include <exiv2/exif.hpp>
#include <exiv2/image.hpp>
#include <exiv2/version.hpp>

#include <memory>
#include <string>

using Exiv2::Image;
using Exiv2::ImageFactory;

std::string exiv2_version() {
return Exiv2::versionString();
}


void set_dpi(const std::string &filename, int x, int y){
std::unique_ptr<Exiv2::Image> image = ImageFactory::open(filename);
void set_dpi(const std::string &filename, int x_res, int y_res){
const std::unique_ptr<Exiv2::Image> image = ImageFactory::open(filename);

image->readMetadata();

Exiv2::ExifData metadata = image->exifData();

metadata["Exif.Image.XResolution"] = Exiv2::URational(x, 1);
metadata["Exif.Image.YResolution"] = Exiv2::URational(y, 1);
metadata["Exif.Image.XResolution"] = Exiv2::URational(x_res, 1);
metadata["Exif.Image.YResolution"] = Exiv2::URational(y_res, 1);
metadata["Exif.Image.ResolutionUnit"] = 2;
image->setExifData(metadata);
image->writeMetadata();
Expand Down
4 changes: 2 additions & 2 deletions src/py3exiv2bind/core/glue/glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef SUPERBUILD_GLUE_H
#define SUPERBUILD_GLUE_H

#include <string>
#include <map>
#include <string>

struct metadata_chunk {

Expand All @@ -19,6 +19,6 @@ struct metadata_chunk {

std::string exiv2_version();

void set_dpi(const std::string &filename, int x, int y);
void set_dpi(const std::string &filename, int x_res, int y_res);

#endif //SUPERBUILD_GLUE_H
6 changes: 3 additions & 3 deletions tests/test-core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ TEST_CASE("bad tiff file with set_dpi raises"){
corruptedFile.open(bad_file, std::ios::binary);
OtherDataFormat packet{3, 3, 3, 1.2};
int number = 444;
const char header = 'I';
constexpr char header = 'I';
corruptedFile.write(&header, sizeof(char ));
corruptedFile.write(&header, sizeof(char ));
corruptedFile.write((char*) &number, sizeof(int ));
corruptedFile.write((char *) &packet, sizeof(OtherDataFormat));
corruptedFile.write(reinterpret_cast<char *>(&number), sizeof(int ));
corruptedFile.write(reinterpret_cast<char *>(&packet), sizeof(OtherDataFormat));
corruptedFile.close();
REQUIRE_THROWS_AS(set_dpi(bad_file, 100, 100), Exiv2::Error);
}
Expand Down
Loading
Loading