#50957 Issue 50954 - Port buildnum.pl to python
Closed 3 years ago by spichugi. Opened 4 years ago by mreynolds.
mreynolds/389-ds-base issue50954  into  master

file modified
+2 -2
@@ -13,7 +13,7 @@ 

  #

  

  PYTHON := python3

- BUILDNUM := $(shell perl $(srcdir)/buildnum.pl)

+ BUILDNUM := $(shell $(srcdir)/buildnum.py)

  NQBUILDNUM := $(subst \,,$(subst $(QUOTE),,$(BUILDNUM)))

  DEBUG_DEFINES = @debug_defs@

  DEBUG_CFLAGS = @debug_cflags@
@@ -627,7 +627,7 @@ 

  endif

  

  dist_noinst_DATA = \

- 	$(srcdir)/buildnum.pl \

+ 	$(srcdir)/buildnum.py \

  	$(srcdir)/ldap/admin/src/*.in \

  	$(srcdir)/ldap/admin/src/scripts/*.in \

  	$(srcdir)/ldap/admin/src/scripts/*.ldif \

file removed
-62
@@ -1,62 +0,0 @@ 

- #!/usr/bin/perl

- # --- BEGIN COPYRIGHT BLOCK ---

- # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.

- # Copyright (C) 2005 Red Hat, Inc.

- # All rights reserved.

- #

- # License: GPL (version 3 or any later version).

- # See LICENSE for details. 

- # --- END COPYRIGHT BLOCK ---

- 

- #--------------------------------------------

- # buildnum.pl

- #

- # Generates a dated build number and writes

- # out a buildnum.dat file in a user specified

- # subdirectory.

- #

- # Usage: buildnum.pl -p <platform dir>

- #--------------------------------------------

- 

- use Getopt::Std;

- use FileHandle;

-                                                                                              

- autoflush STDERR 1;

-                                                                                              

- getopts('p:H');

-                                                                                              

- if ($opt_H) {exitHelp();}

- 

- # Load arguments

- $platdir = $opt_p;

- 

- # Get current time

- @now = gmtime($ENV{SOURCE_DATE_EPOCH} || time);

- 

- # Format buildnum as YYYY.DDD.HHMM

- $year = $now[5] + 1900;

- $doy = $now[7] + 1;

- if ($doy < 100) { $doy = 0 . $doy; }

- $tod = $now[2] . $now[1];

- $buildnum = "$year.$doy.$tod";

- 

- if ($platdir) {

-     # Write buildnum.dat

-     $buildnum_file = "./$platdir/buildnum.dat";

-     open(BUILDNUM,">$buildnum_file") || die "Error: Can't create $buildnum_file: $!\n";

-     print BUILDNUM "\\\"$buildnum\\\"";

-     close(BUILDNUM);

- } else {

-     print "\\\"$buildnum\\\"";

- }

- 

- #---------- exitHelp subroutine ----------

- sub exitHelp {

-     print(STDERR "$0: Generates a dated build number.

- 

-     \tUsage: $0 -p <platform>

- 

-     \t-p <platform>             Platform subdirectory.

-     \t-H                        Print this help message\n");

-     exit(0);

- }

file added
+28
@@ -0,0 +1,28 @@ 

+ #!/usr/bin/python3

+ # --- BEGIN COPYRIGHT BLOCK ---

+ # Copyright (C) 2020 Red Hat, Inc.

+ # All rights reserved.

+ #

+ # License: GPL (version 3 or any later version).

+ # See LICENSE for details.

+ # --- END COPYRIGHT BLOCK ---

+ 

+ # Generate a build number in the format YYYY.DDD.HHMM

+ 

+ import os

+ import time

+ 

+ SDE = os.getenv('SOURCE_DATE_EPOCH')

+ if SDE is not None:

+     obj = time.gmtime(SDE)

+ else:

+     obj = time.gmtime()

+     

+ year = obj[0]

+ doy = obj[7]

+ if doy < 100:

+     doy = "0" + str(doy)

+ tod = str(obj[3]) + str(obj[4])

+ buildnum = f"{year}.{doy}.{tod}"

+ 

+ print(f'\\"{buildnum}\\"', end = '')

Description:

Replace buildnum.pl with a python version so we can continue to remove perl dependencies.

relates: https://pagure.io/389-ds-base/issue/50954

Shouldn't this be shell python?

Beside that one comment (which probably necesitates a retest ^^;) you have my ack

Shouldn't this be shell python?

Hmm, it does work as is, but it's definitely not right :-p Let me rework and test it....

rebased onto 3deb6ad

4 years ago

Shouldn't this be shell python?

Fixed, and tests are good. Merging...

Pull-Request has been merged by mreynolds

4 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/4010

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago