Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ if (TARGET Gui)
ROOT_EXECUTABLE(rootbrowse src/rootbrowse.cxx LIBRARIES RIO Core Rint Gui)
endif()
ROOT_EXECUTABLE(rootcp src/rootcp.cxx LIBRARIES RIO Tree Core Rint)
ROOT_EXECUTABLE(rootrm src/rootrm.cxx LIBRARIES RIO Core Rint)
ROOT_EXECUTABLE(rootls src/rootls.cxx LIBRARIES RIO Tree Core Rint ROOTNTuple)

ROOT_ADD_TEST_SUBDIRECTORY(test)
30 changes: 0 additions & 30 deletions main/python/cmdLineUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python/22434262#22434262
# Thanks J.F. Sebastian !!

from contextlib import contextmanager
import os
import sys
from time import sleep

Check failure on line 19 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F401)

main/python/cmdLineUtils.py:19:18: F401 `time.sleep` imported but unused
from itertools import zip_longest

Check failure on line 20 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F401)

main/python/cmdLineUtils.py:20:23: F401 `itertools.zip_longest` imported but unused

Check failure on line 20 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

main/python/cmdLineUtils.py:16:1: I001 Import block is un-sorted or un-formatted

def fileno(file_or_fd):
"""
Expand Down Expand Up @@ -81,10 +81,10 @@
ROOT.PyConfig.IgnoreCommandLineOptions = True
ROOT.gROOT.GetVersion()

import argparse

Check failure on line 84 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

main/python/cmdLineUtils.py:84:1: E402 Module level import not at top of file
import glob

Check failure on line 85 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

main/python/cmdLineUtils.py:85:1: E402 Module level import not at top of file
import fnmatch

Check failure on line 86 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

main/python/cmdLineUtils.py:86:1: E402 Module level import not at top of file
import logging

Check failure on line 87 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

main/python/cmdLineUtils.py:87:1: E402 Module level import not at top of file

Check failure on line 87 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

main/python/cmdLineUtils.py:84:1: I001 Import block is un-sorted or un-formatted

LOG_FORMAT = "%(levelname)s: %(message)s"
logging.basicConfig(format=LOG_FORMAT)
Expand Down Expand Up @@ -328,12 +328,12 @@
Open a ROOT file (like openROOTFile) with the possibility
to change compression settings
"""
if compress != None and os.path.isfile(fileName):

Check failure on line 331 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E711)

main/python/cmdLineUtils.py:331:20: E711 Comparison to `None` should be `cond is not None`
logging.warning("can't change compression settings on existing file")
return None
mode = "recreate" if recreate else "update"
theFile = openROOTFile(fileName, mode)
if compress != None:

Check failure on line 336 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E711)

main/python/cmdLineUtils.py:336:20: E711 Comparison to `None` should be `cond is not None`
theFile.SetCompressionSettings(compress)
return theFile

Expand Down Expand Up @@ -1177,33 +1177,3 @@

# End of ROOTPRINT
##########

##########
# ROOTRM


def _removeObjects(fileName, pathSplitList, interactive=False, recursive=False):
retcode = 0
rootFile = openROOTFile(fileName, "update")
if not rootFile:
return 1
for pathSplit in pathSplitList:
retcode += deleteRootObject(rootFile, pathSplit, interactive, recursive)
rootFile.Close()
return retcode


def rootRm(sourceList, interactive=False, recursive=False):
# Check arguments
if sourceList == []:
return 1

# Loop on the root files
retcode = 0
for fileName, pathSplitList in sourceList:
retcode += _removeObjects(fileName, pathSplitList, interactive, recursive)
return retcode


# End of ROOTRM
##########
48 changes: 0 additions & 48 deletions main/python/rootrm.py

This file was deleted.

16 changes: 13 additions & 3 deletions main/src/RootObjTree.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "wildcards.hpp"

#include <TFile.h>
#include <TSystem.h>

#include <ROOT/StringUtils.hxx>

Expand All @@ -27,10 +28,19 @@ ROOT::CmdLine::GetMatchingPathsInFile(std::string_view fileName, std::string_vie
ROOT::CmdLine::RootSource source;
source.fFileName = fileName;
auto &nodeTree = source.fObjectTree;
nodeTree.fFile =
std::unique_ptr<TFile>(TFile::Open(std::string(fileName).c_str(), "READ_WITHOUT_GLOBALREGISTRATION"));
const char *fileMode = "READ_WITHOUT_GLOBALREGISTRATION";
const std::string fileNameStr { fileName };
if (flags & kOpenFilesAsWritable) {
// There is no way to open a file for writing only if the file already exists, so we need to manually check first.
if (gSystem->AccessPathName(fileNameStr.c_str(), kWritePermission)) {
source.fErrors.push_back("File '" + fileNameStr + "' does not exist or is not writable.");
return source;
}
fileMode = "UPDATE_WITHOUT_GLOBALREGISTRATION";
}
nodeTree.fFile = std::unique_ptr<TFile>(TFile::Open(fileNameStr.c_str(), fileMode));
if (!nodeTree.fFile || nodeTree.fFile->IsZombie()) {
source.fErrors.push_back("Failed to open file");
source.fErrors.push_back("Failed to open file '" + fileNameStr + "'");
return source;
}

Expand Down
1 change: 1 addition & 0 deletions main/src/RootObjTree.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ enum EGetMatchingPathsFlags {
/// Recurse into subdirectories when matching objects
kRecursive = 1 << 0,
kIgnoreFailedMatches = 1 << 1,
kOpenFilesAsWritable = 1 << 2,
};

/// Given a file and a "path pattern", returns a RootSource containing the tree of matched objects.
Expand Down
8 changes: 8 additions & 0 deletions main/src/rootls.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,13 @@ int main(int argc, char **argv)
[](const auto &a, const auto &b) { return a.fFileName < b.fFileName; });

// sort leaves by namecycle
bool errors = false;
for (auto &source : args.fSources) {
if (!source.fErrors.empty()) {
errors = true;
for (const auto &err : source.fErrors)
Err() << err << "\n";
}
std::sort(source.fObjectTree.fLeafList.begin(), source.fObjectTree.fLeafList.end(),
[&tree = source.fObjectTree](NodeIdx_t aIdx, NodeIdx_t bIdx) {
const auto &a = tree.fNodes[aIdx];
Expand All @@ -641,4 +647,6 @@ int main(int argc, char **argv)
}

RootLs(args);

return errors;
}
Loading
Loading