Linux
11
Вклад в тег
#!/usr/bin/env python3
import os
import json
s = os.popen("ps axho comm --sort -rss | head -5").read()
service_states = s.split()
count = 0
data = {}
for i in service_states:
count += 1
key = "{#TOPMEMNAME" + str(count) + "}"
data.setdefault("data", []).append({key:i})
print(json.dumps(data, sort_keys=True, indent=2))
{
"data": [
{
"{#TOPMEMNAME1}": "python3"
},
{
"{#TOPMEMNAME2}": "bash"
},
{
"{#TOPMEMNAME3}": "ps"
},
{
"{#TOPMEMNAME4}": "head"
},
{
"{#TOPMEMNAME5}": "sh"
}
]
}
$destinationDir = "D:\"
$mainDir = "new_project"
$subDirs = @("css", "js")
$files = @("index.html", "style.css", "script.js", "script.min.js")
Foreach ($subDir in $subDirs)
{
if (!(Test-Path -Path "$destinationDir/$mainDir/$subDir"))
{
New-Item -Path "$destinationDir/$mainDir/$subDir" -ItemType Directory
}
Foreach ($file in $files)
{
if ($file -match ".$subDir")
{
if (!(Test-Path -Path "$destinationDir/$mainDir/$subDir/$file"))
{
New-Item -Path "$destinationDir/$mainDir/$subDir/$file" -ItemType File
}
}
elseif ($file -match ".html")
{
if (!(Test-Path -Path "$destinationDir/$mainDir/$file"))
{
New-Item -Path "$destinationDir/$mainDir/$file" -ItemType File
}
}
}
}