Skip to content

Commit 12ae88d

Browse files
committed
swapping_ebuilds-0.2.0
1 parent 9673763 commit 12ae88d

File tree

9 files changed

+148
-53
lines changed

9 files changed

+148
-53
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ You can find the ebuild in https://github.com/turulomio/myportage/tree/master/ap
3838

3939
## Changelog
4040

41+
### 0.2.0 (2020-12-31)
42+
43+
* Script converted to a python package
44+
4145
### 0.1.0 (2020-12-13)
4246

4347
* Script migrated to this project from myportage repository

doc/Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = SwappingEbuilds
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = None
41+
PROJECT_NUMBER = 0.2.0
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a

locale/es.po

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: RecPermissions\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-12-31 08:11+0100\n"
11+
"POT-Creation-Date: 2020-12-31 08:28+0100\n"
1212
"PO-Revision-Date: 2018-10-22 18:51+0100\n"
1313
"Last-Translator: root <[email protected]>\n"
1414
"Language-Team: Spanish\n"
@@ -39,6 +39,34 @@ msgstr " * Subelo al repositorio del portage"
3939
msgid "Uninstall command only works in Linux"
4040
msgstr "El comando 'uninstall' solo funciona en Linux"
4141

42+
msgid "{} ({}) [{}] has {} reports ({} per hour) with {} of swap average"
43+
msgstr ""
44+
45+
#, python-brace-format
46+
msgid "Problem parsing: {line}"
47+
msgstr "Problema al parsear: {line}"
48+
49+
msgid "This app logs in /var/lib/swapping_ebuilds.txt when compiling gentoo packages and swap is over an amount of MB. This allow you to change in package.env the number of processors used, to decrease swapping and improve ebuild time compilation"
50+
msgstr ""
51+
52+
msgid "Developed by Mariano Muñoz 2017-{}"
53+
msgstr "Desarrollado por Mariano Muñoz 2017-{}"
54+
55+
msgid "Analyze log"
56+
msgstr ""
57+
58+
msgid "Generate log"
59+
msgstr ""
60+
61+
msgid "Minimum megabytes swap amount to be logged. Default is 500MB"
62+
msgstr ""
63+
64+
msgid "Please add a int to the megabytes argument"
65+
msgstr ""
66+
67+
msgid "No swapping detected"
68+
msgstr "No se ha detectado swapping"
69+
4270
#~ msgid "DESCRIPTION"
4371
#~ msgstr "DESCRIPCIÓN"
4472

locale/fr.po

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: RecPermissions\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2020-12-31 08:11+0100\n"
10+
"POT-Creation-Date: 2020-12-31 08:28+0100\n"
1111
"PO-Revision-Date: 2018-11-03 07:11+0100\n"
1212
"Last-Translator: root <[email protected]>\n"
1313
"Language-Team: French\n"
@@ -38,6 +38,34 @@ msgstr " * Uploader au dépôt de portage"
3838
msgid "Uninstall command only works in Linux"
3939
msgstr "La commande 'désinstaller' marche seulement sur Linux"
4040

41+
msgid "{} ({}) [{}] has {} reports ({} per hour) with {} of swap average"
42+
msgstr ""
43+
44+
#, python-brace-format
45+
msgid "Problem parsing: {line}"
46+
msgstr ""
47+
48+
msgid "This app logs in /var/lib/swapping_ebuilds.txt when compiling gentoo packages and swap is over an amount of MB. This allow you to change in package.env the number of processors used, to decrease swapping and improve ebuild time compilation"
49+
msgstr ""
50+
51+
msgid "Developed by Mariano Muñoz 2017-{}"
52+
msgstr ""
53+
54+
msgid "Analyze log"
55+
msgstr ""
56+
57+
msgid "Generate log"
58+
msgstr ""
59+
60+
msgid "Minimum megabytes swap amount to be logged. Default is 500MB"
61+
msgstr ""
62+
63+
msgid "Please add a int to the megabytes argument"
64+
msgstr ""
65+
66+
msgid "No swapping detected"
67+
msgstr ""
68+
4169
#~ msgid "DESCRIPTION"
4270
#~ msgstr "LA DESCRIPTION"
4371

locale/swapping_ebuilds.pot

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-12-31 08:13+0100\n"
11+
"POT-Creation-Date: 2020-12-31 08:29+0100\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
1515
"Language: \n"
1616
"MIME-Version: 1.0\n"
17-
"Content-Type: text/plain; charset=CHARSET\n"
17+
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"
1919

2020
msgid "New Release:"
@@ -37,3 +37,31 @@ msgstr ""
3737

3838
msgid "Uninstall command only works in Linux"
3939
msgstr ""
40+
41+
msgid "{} ({}) [{}] has {} reports ({} per hour) with {} of swap average"
42+
msgstr ""
43+
44+
#, python-brace-format
45+
msgid "Problem parsing: {line}"
46+
msgstr ""
47+
48+
msgid "This app logs in /var/lib/swapping_ebuilds.txt when compiling gentoo packages and swap is over an amount of MB. This allow you to change in package.env the number of processors used, to decrease swapping and improve ebuild time compilation"
49+
msgstr ""
50+
51+
msgid "Developed by Mariano Muñoz 2017-{}"
52+
msgstr ""
53+
54+
msgid "Analyze log"
55+
msgstr ""
56+
57+
msgid "Generate log"
58+
msgstr ""
59+
60+
msgid "Minimum megabytes swap amount to be logged. Default is 500MB"
61+
msgstr ""
62+
63+
msgid "Please add a int to the megabytes argument"
64+
msgstr ""
65+
66+
msgid "No swapping detected"
67+
msgstr ""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def run(self):
132132
entry_points = {'console_scripts': ['swapping_ebuilds=swapping_ebuilds.main:main',
133133
],
134134
},
135-
install_requires=['humanize'],
135+
install_requires=['humanize', 'psutil'],
136136
data_files=[],
137137
cmdclass={ 'doxygen': Doxygen,
138138
'doc': Doc,

swapping_ebuilds/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from datetime import datetime
2-
__version__ = '0.1.0'
2+
__version__ = '0.2.0'
33
__versiondatetime__ = datetime(2020,12,31,8,9)
44
__versiondate__ = __versiondatetime__.date()
249 Bytes
Binary file not shown.

swapping_ebuilds/main.py

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
import sys
44
from os import path
55
from datetime import datetime, timedelta, date
6+
from gettext import translation
67
from humanize import filesize
8+
from pkg_resources import resource_filename
79
from psutil import swap_memory, process_iter
810
from time import sleep
11+
from swapping_ebuilds.__init__ import __version__, __versiondate__
912

10-
__version__="0.1.0.dev"
11-
__versiondatetime__=datetime(2020,12,13,17,44)
12-
__versiondate__=__versiondatetime__.date()
13+
try:
14+
t=translation('swapping_ebuilds', resource_filename("swapping_ebuilds","locale"))
15+
_=t.gettext
16+
except:
17+
_=str
1318

1419

1520
class SetPackages:
@@ -43,7 +48,7 @@ def read_file(self):
4348

4449
def print(self):
4550
for p in self.arr:
46-
print ("{} ({}) [{}] has {} reports ({} per hour) with {} of swap average".format(p.datetime(), p.duration(),p.name(),p.num_reports(), int(p.reports_per_hour()),filesize.naturalsize(int(p.average_swap()))))
51+
print (_("{} ({}) [{}] has {} reports ({} per hour) with {} of swap average").format(p.datetime(), p.duration(),p.name(),p.num_reports(), int(p.reports_per_hour()),filesize.naturalsize(int(p.average_swap()))))
4752

4853

4954
class Package:
@@ -94,53 +99,55 @@ def init__from_line(self,line):
9499
self.swap=int(line.split(" [")[1].split("] ")[1])
95100
return self
96101
except:
97-
print("Problem parsing: {}".format(line))
102+
print(_(f"Problem parsing: {line}"))
98103
return None
99104

100105
def __repr__(self):
101106
return "{} {} {}".format(self.datetime,self.name,self.swap)
102107
####################################################################################################
103108

104-
description="This app logs in /var/lib/swapping_ebuilds.txt when compiling gentoo packages and swap is over an amount of MB. This allow you to change in package.env the number of processors used, to decrease swapping and improve ebuild time compilation"
105-
epilog="Developed by Mariano Muñoz 2017-{}".format(__versiondate__.year)
106-
parser=argparse.ArgumentParser(description=description,epilog=epilog)
107-
parser.add_argument('--version',action='version', version=__version__)
108-
group1=parser.add_mutually_exclusive_group(required=True)
109-
group1.add_argument('--analyze', help='Analyze log', action='store_true', default=False)
110-
group1.add_argument('--get', help='Generate log', action='store_true',default=False)
111-
parser.add_argument('--megabytes', help='Minimum megabytes swap amount to be logged. Default is 500MB', action='store', default=500,metavar="MB")
112-
args=parser.parse_args()
113-
114-
try:
115-
args.megabytes=int(args.megabytes)
116-
except:
117-
print("Please add a int to the megabytes argument")
118-
sys.exit(0)
119109

120-
filename="/var/lib/swapping_ebuilds.txt"
121-
122-
if args.get:
123-
while True:
124-
package=""
125-
try:
126-
for proc in process_iter():
127-
for word in proc.cmdline():
128-
if word.endswith("] sandbox"):
129-
package=word.replace(" sandbox","")
130-
except:
131-
pass
132-
133-
used=swap_memory().used
134-
if used>args.megabytes*1024*1024:
135-
f=open(filename,"a")
136-
f.write(f"{datetime.now()} {package} {used}\n")
137-
f.close()
138-
print (f"{datetime.now()} {package} {filesize.naturalsize(used)} Logging...")
139-
sleep(60)
140-
141-
if args.analyze:
142-
if path.exists(filename)==False:
143-
print("No swapping detected")
110+
def main():
111+
description=_("This app logs in /var/lib/swapping_ebuilds.txt when compiling gentoo packages and swap is over an amount of MB. This allow you to change in package.env the number of processors used, to decrease swapping and improve ebuild time compilation")
112+
epilog=_("Developed by Mariano Muñoz 2017-{}").format(__versiondate__.year)
113+
parser=argparse.ArgumentParser(description=description,epilog=epilog)
114+
parser.add_argument('--version',action='version', version=__version__)
115+
group1=parser.add_mutually_exclusive_group(required=True)
116+
group1.add_argument('--analyze', help=_('Analyze log'), action='store_true', default=False)
117+
group1.add_argument('--get', help=_('Generate log'), action='store_true',default=False)
118+
parser.add_argument('--megabytes', help=_('Minimum megabytes swap amount to be logged. Default is 500MB'), action='store', default=500,metavar="MB")
119+
args=parser.parse_args()
120+
121+
try:
122+
args.megabytes=int(args.megabytes)
123+
except:
124+
print(_("Please add a int to the megabytes argument"))
144125
sys.exit(0)
145-
set=SetPackages()
146-
set.print()
126+
127+
filename="/var/lib/swapping_ebuilds.txt"
128+
129+
if args.get:
130+
while True:
131+
package=""
132+
try:
133+
for proc in process_iter():
134+
for word in proc.cmdline():
135+
if word.endswith("] sandbox"):
136+
package=word.replace(" sandbox","")
137+
except:
138+
pass
139+
140+
used=swap_memory().used
141+
if used>args.megabytes*1024*1024:
142+
f=open(filename,"a")
143+
f.write(f"{datetime.now()} {package} {used}\n")
144+
f.close()
145+
print (f"{datetime.now()} {package} {filesize.naturalsize(used)} Logging...")
146+
sleep(60)
147+
148+
if args.analyze:
149+
if path.exists(filename)==False:
150+
print(_("No swapping detected"))
151+
sys.exit(0)
152+
set=SetPackages()
153+
set.print()

0 commit comments

Comments
 (0)