Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
latex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gerhard Gonter
latex
Commits
d93838c9
Commit
d93838c9
authored
Jan 19, 2018
by
Gerhard Gonter
Browse files
Options
Downloads
Patches
Plain Diff
worker for pdf conversion
parent
46d197cb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lc1.pl
+122
-0
122 additions, 0 deletions
lc1.pl
with
122 additions
and
0 deletions
lc1.pl
0 → 100755
+
122
−
0
View file @
d93838c9
#!/usr/bin/perl
use
strict
;
use
Filesys::Notify::
Simple
;
use
File::
Find
;
my
$work_dir
=
'
.
';
my
@old_jobs
=
();
check_old_jobs
();
watch
();
exit
(
0
);
sub
watch
{
my
$watcher
=
Filesys::Notify::
Simple
->
new
([
$work_dir
]);
while
(
1
)
{
print
__LINE__
,
"
watching ...
\n
";
$watcher
->
wait
(
sub
{
for
my
$event
(
@
_
)
{
my
$path
=
$event
->
{
path
};
# full path of the file updated
print
__LINE__
,
"
path=[
$path
]
\n
";
if
(
$path
=~
m#^.*/([\w\d]+)/Tex/([\w\d]+\.tex)$#
)
{
my
(
$job
,
$tex_file
)
=
(
$
1
,
$
2
);
print
__LINE__
,
"
job=[
$job
] tex_file=[
$tex_file
]
\n
";
pdf2latex
(
$job
,
$tex_file
);
}
elsif
(
$path
=~
m#/var/www/html/dlbt/DLBTUploads/TeiConverter/lc1.pl$#
)
{
print
"
restarting
\n
";
exec
(
$
0
);
}
}
});
}
}
sub
check_tex_file
{
my
$path
=
$
File::Find::
name
;
# print __LINE__, " path=[$path]\n";
if
(
$path
=~
m#^.*/([\w\d]+)/Tex/([\w\d]+\.tex)$#
)
{
my
(
$job
,
$tex_file
)
=
(
$
1
,
$
2
);
my
$pdf_file
=
join
('
/
',
$job
,
'
Pdf
',
"
$job
.pdf
");
push
(
@old_jobs
,
[
$job
,
$tex_file
,
$pdf_file
]);
}
0
;
}
sub
check_old_jobs
{
find
(
\
&check_tex_file
,
$work_dir
);
# find( { wanted => \&check_tex_file }, $work_dir);
foreach
my
$item
(
@old_jobs
)
{
my
(
$job
,
$tex_file
,
$pdf_file
)
=
@$item
;
if
(
-
f
$pdf_file
)
{
print
__LINE__
,
"
job=[
$job
] pdf_file=[
$pdf_file
] already exists, skipping;
\n
";
}
else
{
# print __LINE__, " job=[$job] tex_file=[$tex_file]\n";
pdf2latex
(
$job
,
$tex_file
);
}
}
}
sub
pdf2latex
{
my
$jobname
=
shift
;
my
$tex_file
=
shift
;
my
$tex_path
=
"
$jobname
/Tex/
$tex_file
";
my
$file_info
=
`
/usr/bin/file
$tex_path
2>&1
`;
chop
(
$file_info
);
# print __LINE__, " file_info: [$tex_path] [$file_info]\n";
unless
(
$file_info
=~
m#LaTeX 2e document#
)
{
print
__LINE__
,
"
not a LaTeX file, ignored: [
$file_info
]
\n
";
return
undef
;
}
my
$pdf_dir
=
"
$jobname
/Pdf
";
unless
(
-
d
$pdf_dir
)
{
print
__LINE__
,
"
creating pdf_dir=[
$pdf_dir
]
\n
";
system
('
mkdir
',
$pdf_dir
);
}
# pdflatex -interaction=nonstopmode -jobname PS293242 -output-directory PS293242/Pdf/ PS293242/Tex/document.tex
my
@convert
=
(
qw(/usr/bin/pdflatex -interaction=nonstopmode -jobname)
,
$jobname
,
'
-output-directory
',
$pdf_dir
,
$tex_path
);
my
$media_dir
=
"
$jobname
/Tex/media
";
if
(
-
d
$media_dir
)
{
print
__LINE__
,
"
creating symlink media to [
$media_dir
]
\n
";
system
('
ln
',
'
-s
',
$media_dir
,
'
media
')
}
print
"
converting: [
",
join
('
',
@convert
),
"
]
\n
";
sleep
(
5
);
system
(
@convert
);
if
(
-
d
$media_dir
)
{
print
__LINE__
,
"
removing symlink to [
$media_dir
]
\n
";
unlink
('
media
')
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment